473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memorystream bytearray bitmap

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
4 10572
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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5851
by: Gambler | last post by:
Hi, I'm trying to download a memorystream to a .csv file on the users desktop. When I go to write out the memorystream through the byte array it seems to truncate at 1024 and I don't know how to...
8
4533
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
7
2389
by: Robson Carvalho Machado | last post by:
Does anyone knows how to CAST this SQL Response into a MemoryStream ?? When executing below code an error message says "Specified cast is not valid" I need to put this into MemoryStream to use it...
11
4443
by: Rasmus Teglgaard | last post by:
Hi I need to know how to store the OpenfileDialog.OpenFile() in a memorystream. Do I need to do some kind of conversion before this works I can't write dim mem as new memorystream( mem =...
2
2117
by: SQLScott | last post by:
For some reason I am drawing a blank on this, so I would be extremely greatful if someone could help me out. I am trying to get a MemoryStream out of a Byte array. How do I get it back out? ...
1
2495
by: vbdotnetmania | last post by:
I have a memorystream of a bitmap, I want to send this over the network to a client app so it can receive the bitmap, I am dabbling with sockets and tcpclient's and ahve got a connection going but...
2
16017
by: Bruce D | last post by:
I'm having a problem saving my bitmap in my MySQL database. Apparently it's too big...but it shouldn't be. Here's what I got: Dim bmpDocument As Bitmap = Bitmap.FromHbitmap(hDibCopy) ' get...
3
9177
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As...
13
2832
by: Don | last post by:
When I run the following code, the MemoryStream's Position is always set to 762 instead of 0, which is what I would expect: Dim bmp As Image Dim ms As MemoryStream bmp = New...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.