Hope someone can help...
I am storing images in an SQL database using a VARBINARY column.
It is stored OK and I can retrieve it but I cannot seem to get it to display in a PictureBox control.
When I set the picturebox image it seems to get set OK and I can actually save the picture box image to a file no problem but it will not display it.
Sure it is something obvious but for the life of me I cannot see what is wrong with the code:.
Dim bImage As Byte() = DirectCast(oCmd.ExecuteScalar(), Byte())
If bImage Is Nothing Then
Dim ms As New IO.MemoryStream
ms.Write(bImage, 0, bImage.Length)
Dim bitmap As New Bitmap(ms)
pictureBox1.Image = bitmap
Dim sf As New SaveFileDialog
If sf.ShowDialog() = DialogResult.OK Then
As said, the SQL returns data which is then converted to a bitmap.
Everything looks OK when inspecting the objects, i.e. format, height, width etc...
The pictureBox1.Image.Save works perfectly and the original image can be viewed from file explorer just fine.
So... why does the pictureBox1 not show my image?
What I have tried:
Checked my code carefully, sure it is OK, googled everything I can think of.
Tried all possible methods to load the image; FromStream / FromFile etc...