我知道每个像素的RGB值,那么如何在C#中通过这些值创建图片呢?我看到了一些类似这样的例子:
public Bitmap GetDataPicture(int w, int h, byte[] data)
{
Bitmap pic = new Bitmap(this.width, this.height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Color c;
for (int i = 0; i < data.length; i++)
{
c = Color.FromArgb(data[i]);
pic.SetPixel(i%w, i/w, c);
}
return pic;
}
但它并不起作用。
我有一个二维数组,像这样:
1 3 1 2 4 1 3 ...
2 3 4 2 4 1 3 ...
4 3 1 2 4 1 3 ...
...
每个数字对应一个RGB值,例如,1 => {244,166,89},2 => {54,68,125}。