By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

Memorystream bytearray bitmap

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
"vbdotnetmania" wrote:
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.

Nov 21 '05 #2

P: n/a
> 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.

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.

Nov 21 '05 #3

P: n/a
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

"Cor Ligthert" wrote:
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.

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.


Nov 21 '05 #4

P: n/a
Hi,

Try this.

bitmapbytestream = ms.GetBuffer

Ken
------------------
"vbdotnetmania" <vb***********@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
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.
"vbdotnetmania" wrote:
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.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.