problem saving image to database

M

Martin Horn

Hi all,

I'm trying to save a picturebox image to a database. This is part of the
code I'm using:-

<snip>
Private drv As DataRowView
Private dr As MainDataSet.OrdersRow

If PictureBox.Image IsNot Nothing Then
dr.Pic = CreateByteImage()
End If
<snip>

Private Function CreateByteImage() As Byte()
Dim ms As New IO.MemoryStream
PictureBox.Image.Save(ms, PictureBox.Image.RawFormat)

Dim arrImage() As Byte = ms.GetBuffer
ms.Close()

Return arrImage
End Function

The problem is it fails on the PictureBox.Image.Save line with the error -

Value cannot be null.
Parameter name: encoder

As far as I can tell I'm not passing a NULL reference, can anyone tell me
where I might be going wrong?

Thanks and kind regards,

Martin Horn
 
M

Martin Horn

I sorted it by changing the offending line to :-

PictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)

I'm not entirely certain why I had to, or what problems it will cause me
later, but it works so...

Regards,

Martin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top