Search code examples
bitmapcompact-framework

Constructor for Bitmap from Stream is too slow in compact framework 1


I have 'png' image with size 200x200. 8bit color. Image size is 10k. Image is in memory as byte array. Calling Bitmap bmp = new Bitmap(new MemoryStream(bytes)); costs me about 60 milliseconds. It seems to long for such image size. I know that PNG is compressed image but still think 60 milliseconds is too much time. Does anybody know faster way to construct Bitmap from byte[] ?


Solution

  • This might not really be the answer you're looking for, but it is too long for comments.

    I found that on my device the first time loading an image takes twice as long as subsequent images.

    The Bitmap constructors accept a filename or a Stream which probably show the same performance. I Also tried loading an image using unmanaged code (a .bmp file for now) but Bitmap.FromHbitmap() takes more time (35ms) than loading the image from disk using SHLoadDIBitmap (17ms)!

    So as far as I can tell, whatever it is doing, there is no way to get a Bitmap object without that penalty. Perhaps by using unmanaged code to load and display the images you might be able to speed things up, but as far as I can tell the .png filter is behind a COM interface which requires quite some time to get right in .NET.