Picture Box oddities

  • Thread starter Thread starter Noble Bell
  • Start date Start date
N

Noble Bell

I have an app with 4 picture box controls on it and I need to load images
into the picture boxes. I have the picture boxes set to 216,162 in size and
the property set to "Stretch Image". While loading image sizes of 800x600
there is not a problem but when I try to load an image size that is 166x1200
everything blows up and tells me it is throwing an out of memory error. How
can this be when the 800x600 image is only a few "k" smaller in size than the
1600x1200 image?

Thanks in advance,
 
800x600 is a lot more than just a few k smaller than 1600x1200. Let's
assume the image is only 16bpp color depth (and it could be 24).

800x600 = 240,000 pixels * 2 byes per pixel = 480k bitmap;
1600x1200 = 1,920,000 pexels * 2 bytes per pixel = 4MB bitmap;

If you have 4 of these then we're talking 16MB needed just to hold the
bitmaps you want to show. I can see how that might cause an OOM.

Remember, the PictureBox can't "display" a raw JPG, it has to be
uncompressed to a bitmap to be shipped to GDI and displayed. That's not a
"managed" thing either, this is the case for any image created under any
environment and really under any OS (unless there is a hardware decoder
somewhere in the pipeline, but that's outside the scope of what we're
talking about here).
 
Right you are. Darn, I forgot about the conversion to bitmap first.

--
Noble D. Bell
www.noblesoftware.com



800x600 is a lot more than just a few k smaller than 1600x1200. Let's
assume the image is only 16bpp color depth (and it could be 24).

800x600 = 240,000 pixels * 2 byes per pixel = 480k bitmap;
1600x1200 = 1,920,000 pexels * 2 bytes per pixel = 4MB bitmap;

If you have 4 of these then we're talking 16MB needed just to hold the
bitmaps you want to show. I can see how that might cause an OOM.

Remember, the PictureBox can't "display" a raw JPG, it has to be
uncompressed to a bitmap to be shipped to GDI and displayed. That's not a
"managed" thing either, this is the case for any image created under any
environment and really under any OS (unless there is a hardware decoder
somewhere in the pipeline, but that's outside the scope of what we're
talking about here).


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
 
Back
Top