Microsoft Knowledge Base Email Alertz

KBAlertz.com: (810109) - Describes an error message that you may receive when you try to load an image file that is incomplete or the wrong format by using the Bitmap.FromFile method.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 810109 - Last Review: May 9, 2007 - Revision: 1.3

You receive a "System.OutOfMemoryException" error message when you try to use the Bitmap.FromFile method in the .NET Framework 1.0

SYMPTOMS

When you try to load an image by using the Bitmap.FromFile method in the Microsoft .NET Framework 1.0, you receive the following error message:
An unhandle exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll

CAUSE

This problem may occur when you use the Bitmap.FromFile method and one of the following conditions is true:
  • The image file is corrupted.
  • The image file is incomplete.

    Note You may experience this problem if your application is trying to use the Bitmap.FromFile method on a file stream that is not finished writing to a file.
  • The image file does not have a valid image format or GDI+ does not support the pixel format of the file.
  • The program does not have permissions to access the image file.
  • The BackgroundImage propery is set directly from the Bitmap.FromFile method.

WORKAROUND

To work around this problem, use the following guidelines when you load images by using the Bitmap.FromFile method:
  • Make sure that the image file is not corrupted by opening the image file in another program.
  • Make sure that the image file is complete and that all writing to the image file is completed before you try to load the image file.
  • Make sure that the image file type is a supported image format. For more information about image formats, visit the following Microsoft Developer Network (MSDN) Web site:
    http://msdn2.microsoft.com/en-us/library/ms533814.aspx (http://msdn2.microsoft.com/en-us/library/ms533814.aspx)
  • Examine the permissions of the image file to make sure that the program can access the image file.
  • When you set the BackgroundImage property of a form, use the following example code to set the BackgroundImage property:
    Bitmap bmp=(Bitmap)Image.FromFile(@"Pictures\MyImage.jpg"); 
    this.BackgroundImage=new Bitmap(bmp,bmp.Size);
    
Note When you try to load an image from a file, you can catch the exception and then report the error. For example, the following Microsoft Visual Basic .NET code tries to load an image from a file:
Try
  PictureBox1.Image = Bitmap.From("c:\Badimage.gif")
Catch ex As Exception
  MessageBox.Show("Error loading file","Error")
End Try

STATUS

This behavior is by design.

MORE INFORMATION

For more information about the Bitmap class, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/system.drawing.bitmap(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.drawing.bitmap(vs.71).aspx)

APPLIES TO
  • Microsoft .NET Framework 1.0
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
Keywords: 
kbtshoot kbgdiplus kbprb KB810109
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please