简体   繁体   English

将一维字节数组绘制为图像

[英]Drawing a one-dimensional byte array as an image

I have a one-dimensional array which is a 64x64 image 8 bits. 我有一个一维数组,它是8位的64x64图像。 I want to display this on a Windows Form, but I dont know how to do this. 我想在Windows窗体上显示它,但是我不知道该怎么做。 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 . 但这是行不通的,并且出现了Parameter not valid error

Any help would be greatly appreciated. 任何帮助将不胜感激。

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: 为了在窗体上显示它,您需要在窗体上添加一个PictureBox控件,并设置其Image属性:

pictureBox1.Image = image ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM