1 Replies - 694 Views - Last Post: 20 May 2012 - 04:28 PM Rate Topic: -----

#1 evry1falls  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 25-April 12

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 :
SqlStr = "Update MyTable Set Field1 = '" & Text1.Text & "', PhotoOle = [b]????[/b]"

I'm not able to convert the PictureBox That contains the returned photo to Byes() using :
ImageBytes = Ctype(PictureBox1.Image, Byte())
.... not working .
-Or-
ImageBytes = Ctype(DaraRead!PhotoOle, Byte())
.... not working either.

Is This A Good Question/Topic? 0
  • +

Replies To: A photo in a picturebox

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4405
  • View blog
  • Posts: 12,262
  • Joined: 18-April 07

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.

:)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1