views:

156

answers:

3

I have a jpeg file that is being held as a list(of Byte) Currently I have code that I can use to load and save the jpeg file as either a binary (.jpeg) or a csv of bytes (asadsda.csv).

I would like to be able to take the list(of Byte) and convert it directly to a Picturebox without saving it to disk and then loading it to the picturebox.

If you are curious, the reason I get the picture file as a list of bytes is because it gets transfered over serial via an industrial byte oriented protocol as just a bunch of bytes.

I am using VB.net, but C# example is fine too.

+4  A: 

You could do this:

   var ms = new MemoryStream(byteList.ToArray());
   pictureBox.Image = Image.FromStream(ms);
Mike
+2  A: 

The Image class has a FromStream method and you can create a MemoryStream from a byte array. So:

MemoryStream ms = new MemoryStream(byteList.ToArray());
Image image = Image.FromStream(ms);
shf301
+1  A: 

What you need to do is take the bytes and read them into a stream. You can then use the stream to load the picture box image.

using( MemoryStream ms = new MemoryStream( byteList.ToArray() ) )
{
   this.pictureBox1.Image = Image.FromStream( ms );
}
Justin