It doesn't look like you are writing any bytes to the MemoryStream to create an image from...
Main Topics
Browse All TopicsI want to move a byte array to a picturebox.image in VB.NET.
I have a machine vision application that calculates an image. The calculations are mathematical and I need to display my calculated array on the screen. I can do it brute force with a loop around the pixelset method:
image1.SetPixel(x, y, Color.FromArgb(255, red, green, blue))
But I need much better performance. I have been trying to stream my bytes from a byte array, but I can't get past the error: "AgumentException was unhandled" for the line:
Drawing.Image.FromStream(m
It seems that Image.FromStream() will not accept a MemoryStream as a Stream. I'm new at VB.NET (an old VB6 guy trying to get with it) and I'm not sure I understand the difference between a Stream and a MemoryStream.
I have also tried to load a Stream from a byte array, but I can't seem to even get started. I have problems when I try to instanciate the Stream (again my VB6 background has me crippled).
Thanks,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The array is filled by an 24 bit RGB USB camera. In VB6 I put a BITMAPINFOHEADER on the front of FrameBuf1 and put it up on the screen with StretchDIBits. To make sure I have valid data (if not an image) I used the code in the snippet below to put FrameBuf1 up on the screen (albiet very slowly).
Right now, my goal is to move the data quickly from a frame grab to the display in an effort to get a critical part of my software running in VB.NET. In the actual application the image will be processed before it is presented.
Thank you for your effort, I really appeciate the help.
I don't believe that you need to use SetPixel, but you need a valid image in the byte array before you construct a MemoryStream from the byte array.
Example which uses a byte array to create a MemoryStream. The Using block calls the MemoryStream.Dispose method to release resources after you are done with the stream.
Using stream As New MemoryStream(frameBuffer)
End Using
I know the SetPixel effort is not the way to go. I just tried that to see if the FrameBuf1 array was a was what I thought it was. It is. You asked if it was a valid image... I think the answer is yes, but maybe I'll play with that idea a bit and see if I can construct an array from an image/bitmap and then feed it into a stream. Maybe that is the instruction I need. Do you think the BITMAPINFOHEADER needs to be on the front of the data array? I'll give that some time, but I think...
My problem has to do with the proper use of Streams. I can not seem to create a stream from an array and then send it through to an image. The problem isn't that the image is corrupted, but rather that the Image.FromStream(ms) fails because the ms parameter is somehow invalid.
The Bitmap class does not work with DIBs (Device Independent Bitmap). You would need to convert the DIB to a Bitmap.
There is one possibility (untested):
http://www.taotekaching.co
Converted from C#:
Business Accounts
Answer for Membership
by: JackOfPHPosted on 2009-07-29 at 05:46:20ID: 24969541
Ok try this one:
Dim FrameBug1() as byte
..... Your code here to feel the byte array with data....
Dim ms as New MemoryStream(FrameBug1)
Picture1.image = image.FromStream(ms)
Cheers,
Joseph