i am trying to retrieve an image from a .mdb database and show it in an image
control.My code is:
Dim cmd As New OleDbCommand("Select * from recents", con)
Dim table As New DataTable
Dim adap As New OleDbDataAdapter(cmd)
adap.Fill(table)
If table.Rows.Count <= 0 Then
Else
For Each row In table.Rows
Dim recentbtn As New Rctsctt.UserControl1
Dim data As Byte() = CType(table.Rows(0)(1), Byte())
Dim strm As MemoryStream = New MemoryStream()
strm.Write(data, 0, data.Length)
strm.Position = 0
Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(strm)
Dim bi As BitmapImage = New BitmapImage()
bi.BeginInit()
Dim ms As MemoryStream = New MemoryStream()
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
ms.Seek(0, SeekOrigin.Begin)
bi.StreamSource = ms
bi.EndInit()
recentbtn.Image.ImageSource = bi
Next
End if
I am getting a `parameter not valid exception in the line :
Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(strm)
Why is this happening ?
Update 1
I opened my .mdb database and saw that the image/picture was saved as a Long binary data'..So, i thought if i could convert the binary data to an
ImageSource`,it might work.So i tried this from here
For Each row In table.Rows
Dim recentbtn As New Rctsctt.UserControl1
Dim picsource() As Byte = CType(row("Pic"), Byte())
Dim bmp As BitmapImage = New BitmapImage
Dim strm As MemoryStream = New MemoryStream
Dim offset As Integer = 1
strm.Write(picsource, offset, picsource.Length - offset)
bmp.BeginInit()
bmp.StreamSource = strm
bmp.EndInit()
recentbtn.Image.ImageSource = bmp
Next
But now i get an error : No imaging component suitable to complete this operation was found.