Memorystream bytearray bitmap

G

Guest

I have the following snippet of code with bm being a succesfully stored bitmap
(not including all the code just the relevant bits)

Dim g As Graphics
Dim g2 As Graphics
Dim bm As Bitmap
Dim bm2 As Bitmap
Dim bitmapbytestream() As Byte
Dim b2() As Byte
Dim ms As New MemoryStream()

bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
bitmapbytestream = ms.ToArray
bm2 = New Bitmap(71, 92)
Dim STRM As New MemoryStream(bitmapbytestream)
bm2 = Bitmap.FromStream(STRM)
pbo1.Image = bm2

I have tried numerous different wys of this but I can only get a black image
displayed in my picturebox pbo1, anybody have any ideas where I am going
wrong?
Thanks,
barry.
 
G

Guest

Hi all,
To anybody interested have found my error and it was not this snippet
of code, problem was with the original bitmap which wasn't stored properly
after all, so this code works fine if anybody wants to utilise it.
 
C

Cor Ligthert

To anybody interested have found my error and it was not this
snippet
of code, problem was with the original bitmap which wasn't stored properly
after all, so this code works fine if anybody wants to utilise it.
Are you sure of that, I see no original bitmap supported to the stream.


 
G

Guest

Well yes and no, Technically you are correct
the code that contained the original bitmap was not included in this code
snippet.
but thought it was obvious that this would need a user would have to provide
their own bitmap as this was not the relevant part of the problem, anyway
guess I can see how confusion could arise.

Anyway to avoid any further confusion and for more ease of readability I
will include the code again with some changes
Adding the extra line bm = pbomain.image - so now a bitmap is being assigned
to bm.
Also removing line bm2 = New Bitmap(71, 92) as it wasn't needed.

Hope this clears things up.

Dim g As Graphics
Dim g2 As Graphics
Dim bm As Bitmap
Dim bm2 As Bitmap
Dim bitmapbytestream() As Byte
Dim b2() As Byte
Dim ms As New MemoryStream()

bm = pbomain.image
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
bitmapbytestream = ms.ToArray
Dim STRM As New MemoryStream(bitmapbytestream)
bm2 = Bitmap.FromStream(STRM)
pbo1.Image = bm2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top