Reputation: 743
I have a one-dimensional array which is a 64x64 image 8 bits. I want to display this on a Windows Form, but I dont know how to do this. Can someone provide a sample code to perform this.
byte [] image = new byte[64*64];
I have tried this:
ImageConverter ic = new ImageConverter();
Image img = (Image)ic.ConvertFrom(image); <--- Parameter not valid error
Bitmap bitmap1 = new Bitmap(img);
bitmap1.SetResolution(64, 64);
e.Graphics.DrawImage(img, 400, 10);
But this doesn't work, and I get a Parameter not valid error
.
Any help would be greatly appreciated.
Upvotes: 1
Views: 1250
Reputation: 10456
You need to first convert your byte array into an image:
byte [] imageBuffer = new byte[64*64];
... populating the byte array...
Image image = null;
using (MemoryStream ms = new MemoryStream(imageBuffer))
{
image = Image.FromStream(ms);
}
In order to show it on your form, you need to add to your form a PictureBox control, amd set it's Image
property:
pictureBox1.Image = image ;
Upvotes: 1