1 Replies - 755 Views - Last Post: 20 May 2012 - 04:28 PMRate Topic:

A photo in a picturebox

Posted 20 May 2012 - 02:51 PM

Hello,
I have a project in VB2010 it is well connected to the database (DB.accdb) access2007.
I'm trying to save the photo into the database table using Binary method.
I am successfully able to (Save, Search).
my problem is in the EDIT button :
I'm supposed to search first to return\display the info+Photo on the form controls (Textbox + PictureBox), now i want to do EDIT, i use sql string :

Replies To: A photo in a picturebox

Re: A photo in a picturebox

Posted 20 May 2012 - 04:28 PM

Try setting up a stream in memory to first write the image to and then from there you can convert it to an array of bytes...

' Create a stream in memory
Using memStream as New MemoryStream
' Save the image from the picturebox (in PNG format) to the memory stream
PictureBox1.Image.Save(memStream, System.Drawing.Imaging.ImageFormat.Png)
' Now you can use the stream to write a byte array
ImageBytes = memStream.ToArray()
' Disposes of the stream automatically
End Using

Give that a try and see if that solves your problem. You can of course use the appropriate image format that works for you when saving the image to the stream in memory.