locked
Out of memory Exception RRS feed

  • Question

  • I'm using this code to retrieve the Picture that is saved in the database But when trying to assign the image from file to PictureBox i Get the Below error 

    "Out Of Memory"

    Please Help me ; Im in urgent situation


           if (!string.IsNullOrEmpty(dt.Rows[0]["NumIcon"].ToString()))
                    {
                        byte[] barrImg = (byte[])dt.Rows[0]["NumIcon"];
                        string strfn = Convert.ToString(DateTime.Now.ToFileTime());
                        FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
                        fs.Write(barrImg, 0, barrImg.Length);
                        fs.Flush();
                        fs.Close();
                        pictureBox1.Image = Image.FromFile(strfn); 
                    }


    Monday, July 15, 2013 8:09 AM

Answers

  • Debugging OOM Exceptons (and understanding why they happen):

    http://blogs.iis.net/webtopics/archive/2009/05/22/troubleshooting-system-outofmemoryexceptions-in-asp-net.aspx

    With images the filesize on disk/network might be a lot smaller then what is needed to store them for display, because several compression and memory saving methods have to be reversed:

    I observerd increases as high as 25 times for .jpg (jpg is really effective for storage) and 7 times for png format (using real world images, the better compression the bigger they become in memory). A loaded images size is comparable to that of a bitmap of full size at the Desktops Color Depth.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    • Marked as answer by Caillen Monday, July 22, 2013 10:36 AM
    Monday, July 15, 2013 11:13 AM

All replies

  • Hi,

    the possible reasons for an out of memory exception by using Image.FromFile() are:

    The file does not have a valid image format.

    -or-

    GDI+ does not support the pixel format of the file.

    See documentation


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    My Forum Threads

    Monday, July 15, 2013 8:23 AM
  • Debugging OOM Exceptons (and understanding why they happen):

    http://blogs.iis.net/webtopics/archive/2009/05/22/troubleshooting-system-outofmemoryexceptions-in-asp-net.aspx

    With images the filesize on disk/network might be a lot smaller then what is needed to store them for display, because several compression and memory saving methods have to be reversed:

    I observerd increases as high as 25 times for .jpg (jpg is really effective for storage) and 7 times for png format (using real world images, the better compression the bigger they become in memory). A loaded images size is comparable to that of a bitmap of full size at the Desktops Color Depth.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    • Marked as answer by Caillen Monday, July 22, 2013 10:36 AM
    Monday, July 15, 2013 11:13 AM
  • I think, your file needs to be of a valid image format and to have an appropriate file extension.

    wizend

    Monday, July 15, 2013 11:51 AM