OutOfMemory exception loading ZIP or JPEG compressed TIFs from file

T

Tim Frawley

I am using a method that was described as the best for avoiding memory
leaks when using MS Picture boxes. The main idea was to use a variable
to load the image from file and then assign the picture box image to
that variable like so:

Dim img as BitMap ' (have tried BitMap and Image)
img = Image.FromFile(OFD.FileName)
PictureBox1.Image = img

This has worked great with my photo album creator as my memory leaks
disappeared like magic.

I have, however, found another issue that I need to work out or find a
workaround for.

If a TIF image has been saved with ZIP or JPEG compression (we are
using Adobe Photoshop) then I get the following Exception when the
variable is loaded From File.

System.OutOfMemoryException: Out of memory.
at System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
at ReadSpecimen.frmReadSpecimen.cmdBrowse_Click(Object sender,
EventArgs e)

Does anyone have any ideas how to make this work with these compressed
formats?

If not does anyone have an idea on how I can detect the compression
properties of a TIF so I can warn the user and avoid the error?

Thanks for any help,

Sincerely,

Timothy Frawley
 
P

Peter Huang [MSFT]

Hi

System.Drawing is built on GDI+. Therefore, it is the underlying GDI+ which
is loading the TIFF. Note that GDI+ frequently returns "out of memory"
errors as a generic indication of error. This might include an unsupported
format, or maybe it really is a memory pressure issue, or it could be
something else entirely.
Here is document about tiff.
We support the baseline TIFF (Part 1 in the document), and much of the
extensions (part 2). But we don't support JPG-compression in TIFF so far.
<http://www.ibr.oeaw.ac.at/beamline/tiff_doc_6_0.pdf>

For your scenario, I think we can use try..catch block to handle the
exception to avoid getting the exception when we are openning some
unsupported image format.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Tim Frawley

Thank you Peter,

As usual your posts are informative and very helpful.

I have already placed a try... catch block around the loading of the
image with an informative message box to the extent that the error may
have been caused by an unsupported image format with appropriate
instructions to the user on how to resolve the issue. This will have
to do.

Thank you again, I appreciate your help very much!

Sincerely,

Tim Frawley
 
P

Peter Huang [MSFT]

Hi

I am glad my suggestion helps you.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top