locked
Image.FromFile causes error on 64-bit machine RRS feed

  • Question

  • I'm writing a Windows Forms application using VB.NET under VS2010.  It needs to load .jpg images into a picturebox.  The line of code is something like mypicturebox.Image = Image.FromFile("foo.jpg").  It runs fine on my XP computer, but when installed on a 64-bit Windows 7 computer, that line of code gives an out of memory error.  (It's not really out of memory.  That message is a general error message.  See http://stackoverflow.com/questions/2610416/is-there-a-reason-image-fromfile-throws-an-outofmemoryexception-for-an-invalid-im/2610506#2610506)  There is a previous version of the program, which was written with VS2005 (and presumably targeting .net framework 2.0).  That version runs on the 64-bit machine fine.  I am targeting framework 3.5.  (I can't target 4.0 because my program is a plug-in for ArcGIS version 9, which is not compatible with framework 4.0.)

    Can anyone shed some light on why the VS2005 version runs on 64-bit Windows 7, but the VS2010 version does not?  Would it help to target an earlier version of .net framework?  I understand that framework 2.0 uses the same CLR as 3.0 and 3.5, so maybe that's not the issue.  I also understand that there are image formats that were supported in earlier versions of Windows, that are no longer supported in later versions, but as far as I know, these files are plain old .jpg.

    Monday, July 18, 2011 10:41 PM

Answers

  • Finally found what was wrong.  It turned out to have nothing to do with the operating system or framework version.  It was trying to read a file that wasn't an image, and as the link above says, you get an inaccurate out-of-memory error when the file is bad format.  Thanks for the reply.

    • Marked as answer by Paul Zhou Tuesday, July 26, 2011 2:14 AM
    Thursday, July 21, 2011 2:15 PM

All replies

  • Have you use CLRProfiler to check whether it is really out of memory?
    Hard hard work, Day day up!
    Wednesday, July 20, 2011 1:27 AM
  • Finally found what was wrong.  It turned out to have nothing to do with the operating system or framework version.  It was trying to read a file that wasn't an image, and as the link above says, you get an inaccurate out-of-memory error when the file is bad format.  Thanks for the reply.

    • Marked as answer by Paul Zhou Tuesday, July 26, 2011 2:14 AM
    Thursday, July 21, 2011 2:15 PM