473,372 Members | 1,045 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 10551
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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.