2 diff blob format reading error

  • Thread starter Thread starter gwafy
  • Start date Start date
G

gwafy

Guest
I have 2 diff. image format stored in db2 database as blob one start with 0000000C6A5020200D0A87 which cannot be displayed in picture box I get error invalid parameters and the other start with FFD8FFE000104A4649460 with no problem.

So, I tried more than 1 solution till I finally succeeded to display both of them as in the below code

But I got both as in Pic. How can I display both Pic. In the right format?





Solution1


OleDbDataAdapter1.Fill(DataSet11, "PORT_IMAGE")

Dim c As Integer = DataSet11.Tables("PORT_IMAGE").Rows.Count

If c > 0 Then


Dim output = New Bitmap(Width, Height)

Dim ImageBytes() As Byte = DataSet11.Tables("PORT_IMAGE").Rows(c - 1)("P_IMAGE")

Dim bitmap As New Bitmap(Width, Height, PixelFormat.Format64bppArgb)

Dim bitmap_data = bitmap.LockBits(New Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format64bppArgb)

Marshal.Copy(ImageBytes, 0, bitmap_data.Scan0, ImageBytes.Length)

Dim i As Integer = 0

Do While (i < ImageBytes.Length)

Dim R As Byte = ImageBytes(i)

Dim G As Byte = ImageBytes((i + 1))

Dim B As Byte = ImageBytes((i + 2))

Dim A As Byte = ImageBytes((i + 3))

ImageBytes(i) = B

ImageBytes((i + 1)) = G

ImageBytes((i + 2)) = R

ImageBytes((i + 3)) = A

i = (i + 4)

Loop

bitmap.UnlockBits(bitmap_data)

Dim imge = CType(bitmap, Image)

PictureBox1.Image = imge

PictureBox1.Refresh()

'Format32bppArgb





Solution 2

Dim output = New Bitmap(Width, Height)

Dim rect = New Rectangle(0, 0, Width, Height)

Dim bmpData = output.LockBits(rect, ImageLockMode.ReadWrite, output.PixelFormat)

Dim ptr = bmpData.Scan0

Marshal.Copy(b, 0, ptr, b.Length)

output.UnlockBits(bmpData)

PictureBox1.Image = output




Solution3

Dim buffer() As Byte = DataSet11.Tables("PORT_IMAGE").Rows(c - 1)("P_IMAGE")

Dim bitmap As New Bitmap(Width, Height, PixelFormat.Format32bppRgb)

Dim bitmap_data = bitmap.LockBits(New Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb)

Marshal.Copy(buffer, 0, bitmap_data.Scan0, buffer.Length)

bitmap.UnlockBits(bitmap_data)

Dim imge = CType(bitmap, Image)

PictureBox1.Image = imge

Continue reading...
 
Back
Top