Hi!
I need to load a list of JPEG images from MS Access to VB.Net unfortunately I can't even load a single picture into VB.Net, I can load BMP pictures but not JPEG. I have found a C# code that does what I wanted.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2156764&SiteID=1
But unfortunately, when I converted the code to VB.Net it does not work.
Upon debugging I found out that the strTemp returns different results in C# and in VB.Net. The VB.Net variable only returns a very small portion of the entire array. With this code I can load BMP images but I can't with JPEG
Here's the converted code
Hope somebody can help. Thanks!
I need to load a list of JPEG images from MS Access to VB.Net unfortunately I can't even load a single picture into VB.Net, I can load BMP pictures but not JPEG. I have found a C# code that does what I wanted.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2156764&SiteID=1
But unfortunately, when I converted the code to VB.Net it does not work.
Upon debugging I found out that the strTemp returns different results in C# and in VB.Net. The VB.Net variable only returns a very small portion of the entire array. With this code I can load BMP images but I can't with JPEG
Here's the converted code
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BITMAP_ID_BLOCK As String = "Bitmap"
Dim JPG_ID_BLOCK As String = "\u00FF\u00D8\u00FF"
'create the command object and store the sql query
aCommand = New OleDbCommand(("select Image from Images where KeyID = " + TextBox1.Text), aConnection)
Dim ms As MemoryStream = New MemoryStream
Dim img() As Byte = CType(aCommand.ExecuteScalar(), Byte())
Dim u8 As Encoding = Encoding.UTF7
Dim strTemp As String = u8.GetString(img)
Dim strVTemp As String = strTemp.Substring(0, 300)
Dim iPos As Integer = -1
Dim test As Integer = strVTemp.IndexOf(JPG_ID_BLOCK)
If (strVTemp.IndexOf(BITMAP_ID_BLOCK) = -1) Then
' Find the starting block of the image
iPos = strVTemp.IndexOf(JPG_ID_BLOCK)
Else
iPos = 78
End If
' From the position above get the new image
If (iPos <> -1) Then
ms.Write(img, iPos, (img.Length - iPos))
Me.PictureBox1.Image = Image.FromStream(ms)
End If
ms.Close()
End Sub
Last edited by a moderator: