各位大虾,小妹最近用C#写了个小程序,按行列数循环写入一个数组,数组每个值是从0-255,得到了一个二进制文件,现在我想把这个文件在picturebox里面以灰度图(黑白的)的形式显示出来,不知道该怎么做?麻烦麻烦各位不吝赐教,小妹感激不尽~~
解决方案 »
- 怎么实现界面的打印功能?
- c# 引用excel问题~~~
- 写一条sql语句怎样把它放到table中
- 求算法高手,如何隔一个取一个,把List<string>中的String,填充进自己所定义的类中??
- 如何利用sqlcommand的Parameters.add,向float的字段中插入null?
- 求文本编辑器源码
- 通过UdpClient来监听本地的一个端口,通过什么方式来获取数据发送方的IP地址和端口呢?
- 寻找辽宁盘锦.net程序员!
- 有两个表,是一对多的主从关系,在Form中分别对应两个DataGrid,如果把这两个datagrid也变成主从关系?
- listview中如何邦定数据?
- 自己定义的类中有个串口,现在需要关闭掉,请高手看看怎么办
- 如何修改xml节点的名字(name)而非属性值
{
Bitmap bmp = new Bitmap(buf,Width, buf.Length);
for(int i=0;i<bmp.Width;i++)
for (j = 0; j < bmp.Height; j++)
{
Color c=new Color();
c.R=c.G=c.B=buf[i,j];
bmp.SetPixel(i,j,c);
}
return bmp;
}
{
Bitmap bmp = new Bitmap((int)buf.Rank, (int)buf.Length);
for(int i=0;i<bmp.Width;i++)
for (int j = 0; j < bmp.Height; j++)
{
Color c=Color.FromArgb(buf[i,j],buf[i,j],buf[i,j]);
bmp.SetPixel(i,j,c);
}
return bmp;
}
//一维数组(0-255)显示为灰度图
private void button1_Click(object sender, EventArgs e)
{
//生成数据
byte[] bytes = new byte[100 * 100];
Random rnd = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(rnd.Next(255));
} //填充灰度图 int k = 0;
Bitmap bmp = new Bitmap(100, 100);
for (int y = 1; y < 99; y++)
{
for (int x = 1; x < 99; x++)
{
int colorValue = bytes[k++];
bmp.SetPixel(x, y, Color.FromArgb(colorValue, colorValue, colorValue));
}
} pictureBox1.Image = bmp;
}
{
for (int j = 0; j < 10458; j++)
{
buffer[i, j] = bin.ReadByte(); }
}
if (i == 8729) MessageBox.Show("read done");
Bitmap bmp = new Bitmap(10458, 8729);
for (int m = 0; m < bmp.Height; m++)
for (int n = 0; n < bmp.Width; n++)
{
Color c = Color.FromArgb(buffer[m, n], buffer[m, n], buffer[m, n]);
bmp.SetPixel(n,m,c);
}
pictureBox1.Image = bmp;
}
我用了mngzilin的方法,可是在picturebox里面全是黑色的...不知道怎么回事
new byte[100 * 100];//生成大小为1万的一维数组//如果二维数组
new byte[100 ,100];////填充时用x,y去取
int colorValue = bytes[x-1,y-1];