DATATABLE COLOUMN (IMAGE)OF TYPE SYSTEM.BYTE[] TO MEMORYSTREAM

  • Thread starter Thread starter eliaray
  • Start date Start date
E

eliaray

Guest
Hello everyone,

I have a table in a database that has a coloumn with images (BLOB). What i am trying to do is Binding it to a Datagridview (already done) and on the click event of any row i get the image field of that row displayed in a picture box. I tried many things and tried searching for similar situations but am not able making it work.

The coloumn item are of type System.Byte[] and i am trying to get them to Memorystream and then simply PIC_BOX.Image = Image.FromStream(ms). I tried a couple codes that i thought would work.

However it seems like i am missing something because i get this error:

Code 1:

Dim bytes() As Byte = DGV_ALL_CHEQUES.CurrentRow.Cells("Image").Value

Using ms As New MemoryStream()
Using source As New MemoryStream(bytes)

source.CopyToAsync(ms).GetAwaiter()
PB_BROWSE_IMAGE.Image = Image.FromStream(ms)
End Using
End Using

Code 2:

Dim bytes() As Byte = DGV_ALL_CHEQUES.CurrentRow.Cells("Image").Value

Using ms As New MemoryStream()
Dim count As Integer = 0
While (count < bytes.Length)
ms.WriteByte(bytes(count))
count += 1
End While
PB_BROWSE_IMAGE.Image = Image.FromStream(ms)
End Using

Code 3:

Dim bytes() As Byte = DGV_ALL_CHEQUES.CurrentRow.Cells("Image").Value

Using ms As New MemoryStream()
ms.Write(DGV_ALL_CHEQUES.CurrentRow.Cells("Image").Value, 0, bytes.Length)
PB_BROWSE_IMAGE.Image = Image.FromStream(ms)
End Using


Error for any of the above : Parameter is not valid (line: PB_BROWSE_IMAGE.Image = Image.FromStream(ms))


Thanks in advance for any suggestion.

Continue reading...
 
Back
Top