byte array to image

J

Joey Wu

Dear All

I got a byte array that return from ccd of my device.
It contain a capture image data.
I have to convert it to image type and show it on picturebox.
But, when I try to do this.

picturebox1.image = new bitmap(new memorystream(picByte))

I got a ArgumentException.
Please give me a hand and thanks a lot !!


Joey
 
A

Alex Feinman [MVP]

The Bitmap class consrtuctor expects a formatted (vs. raw) stream. It should
contain the same data as a graphic file would, including a valid header. The
easiest way to create a Bitmap object from raw data is to build the
appropriate BITMAPFILEHEADER and BITMAPINFOHEADER around it. YOu can find a
sample here:
http://www.alexfeinman.com/download.asp?doc=OnTheFlyBitmap.zip
Of interest to you is a function CreateBitmap(int width, int height, byte[]
rawdata)
Its output can be fed to the Bitmap constructor
 

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