OutOfMemory Exception Error

I'm working on a rather complicated program using signature tablets. Someone signs the tablet, displaying their signature on screen. That signature is then broken down into a unicode byte string to be saved into a database. So far, so good. When I open a second form, designed to display entries from the database, it gets as far as the code below and give me an error message saying 'OutOfMemory Exception is unhandled'.

This is the code designed to retrieve the unicode string from the database and turn it back into a signature.

Dim ImgDataAsString

ImgData = RegisterdbDataSet.Time_In_Table.NewTime_In_TableRow.Signature_Data()

Dim bytesAsByte() = System.Text.Encoding.Unicode.GetBytes(ImgData)

FileOpen(1, Environ("temp") &"\Sample.jpg", OpenMode.Binary)

FilePut(1, bytes, ,True,True)

FileClose(1)

SignatureDisplay.Image = System.Drawing.Image.FromFile(Environ("temp") &"\Sample.jpg")

'delete the temporary image file

Kill(Environ("temp") &"\Sample.jpg")

The highlighted line is the line that is giving me the error.

I found this thread (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=667327&SiteID=1 ) which seems to cover the same topic, but it looks like this won't apply here since the image is only 180x110 pixels, therefore less the 1MB in size.

If anyone can help, it would be appreciated.

[3808 byte] By [BortNE24] at [2007-12-25]
# 1

Often times that I've seen that exception be thrown if the file is

a) corrupt (perhaps it is incomplete)

b) in an unsupported format

c) file does not exist or some other access error.

Have you checked to make sure that the image you have is actually an image that say Windows Fax and Viewer or paintbrush can open?

MarcD at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
No. The image is being compiled from a string of unicode characters, so I can't check to see if it will load with Windows Fax and Picture Viewer.
BortNE24 at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3
Sure you can. Put a breakpoint at the line that is throwing the exception. then when the debugger hits that line go take a peek at where you saved the file.
MarcD at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4

Oh.

Thanks Marc. I'm off home now, so I'll check it out first thing tomorrow morning.

BortNE24 at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5

OK, I've found the jpg, but it was empty. When I loaded it into the Windows Fax/Picture Viewer, it came up with 'No Preview Available'.

I'm starting to suspect that the data isn't being saved into the database correctly. When I go into Access, I can see some of the characters that make up the string for the signature, but only 6 of them where there should be a lot more. I'm going to send my code to the manufacturer of the signature tablet and their Software Engineers and see what they say about it.

Thanks for the help Marc.

BortNE24 at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6
In your code make sure you're flushing the file before closing it. And verify the bytes written to the file. After that verify that the file size in windows explorer has some bytes and then perhaps open it in a binary editor and inspect the header. it could be that the header is missing or etc.
MarcD at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 7

Also I noticed that you are converting the data to a string and then to a byte array. This is bound to come into encoding issues with unicode that affect binary data. If the data is binary in ms access it should come out as a byte[] by default. If itn's not being stored in the database as binary - you should probably change it to something that is binary.

MarcD at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...