OutOfMemory exceptions with PictureBox control

  • Thread starter Thread starter rory.groves
  • Start date Start date
R

rory.groves

Got a basic form with a single PictureBox control.

The image has these properties:

Filesize: 55kb
Width: 4000px
Height: 2500px

Yes, the dimensions are large, but its a 2-color image and very small
in size. Why would it throw that error? The included Image Browser
works just fine, with image filesizes much larger (200-500kb).

Here's the exact error:

System.OutOfMemoryException was unhandled
Message="OutOfMemoryException"
StackTrace:
at Microsoft.AGL.Common.MISC.HandleAr()
at System.Drawing.Bitmap._InitFromMemoryStream()
at System.Drawing.Bitmap..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke()
at System.Reflection.RuntimeConstructorInfo.Invoke()
at System.Reflection.ConstructorInfo.Invoke()
at System.Resources.ResourceReader.CreateResource()
at System.Resources.ResourceReader.LoadBitmap()
at System.Resources.ResourceReader.LoadObjectV2()
at System.Resources.ResourceReader.LoadObject()
at System.Resources.RuntimeResourceSet.GetObject()
at System.Resources.ResourceManager.GetObject()
at System.Resources.ResourceManager.GetObject()
at SampleApp.Form1.InitializeComponent()
at SampleApp.Form1..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke()
at System.Reflection.RuntimeConstructorInfo.Invoke()
at System.Reflection.ConstructorInfo.Invoke()
at System.Activator.CreateInstance()
at MyForms.Create__Instance__()
at MyForms.get_Form1()
at SampleApp.Form1.Main()
 
More code would be useful, but there are a few thing to consider. First,
even at 1bpp the image data is still 1.2MB. The compressed size (55k) has
nothing to do with how it fits into a frame buffer.

Depending on how the Image is created in code, the CF may be creating a
16bpp DIB to hold it. That would be 20MB for image data.

The image browser works becasue it knows your device can't possibly have a
4000x2500 pixel screen resolution, so it's creating a thumbnail and ignoring
a vast majority of the image data.
 
This is the generated code,

Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.PictureBox1.Image =
CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
Me.PictureBox1.Location = New System.Drawing.Point(0, 0)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(240, 268)
Me.PictureBox1.SizeMode =
System.Windows.Forms.PictureBoxSizeMode.StretchImage


Are there any controls or code snippits I can look at to emulate the
Image Viewer thumbnail technique?
 
Back
Top