System.OutOfMemoryException when trying to load image into a picturebox

  • 13 years ago
    I am developing an application using VB .NET 2003. The application need to read photo from a smart card using function from a dll. The photo is a JPEG data of size 4000bytes.

    First i declare the function that i need to use as:

    Declare Function Get_Picture Lib "smrtcrd.dll" Alias "_SC_Photo@4" (ByVal pbPhoto() As Byte) As Short

    This is the code snippet:

    Dim photo(4000) As Byte
    Dim i As Short = Get_Picture(photo)
    Dim fNum As Integer
    fNum = FreeFile()
    FileOpen(fNum, "C:\MyFile.gif", OpenMode.Binary, OpenAccess.ReadWrite)
    FilePutObject(fNum, photo)
    FileClose(fNum)
    PictureBox1.Dispose()
    PictureBox1.Image = Image.FromFile("C:\MyFile.gif")

    However, when the last line get executed, a 'System.OutOfMemoryException-Out of Memory' was thrown.

    Any idea why this happened? Please help!





























  • 13 years ago
    You shoudl not be calling

    PictureBox1.Dispose()







Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only 3 numbers of interest to a computer scientist: 1, 0 and infinity”