c# – 像素数据到图像

我有这种格式的列表像素
ArrayList list = new ArrayList();
list.add(Red);
list.add(Blue);
list.add(Green);

我有很多像这样的价值观.我想将数组列表转换为图像..尝试了很多,但没有找到任何适当的材料.

编辑:这可能有所帮助:

List<byte> pic = new List<byte>(); 
for (int j = 0; j < headdata.Count; j++)
{ 
    if(headdata.ElementAt(j).getHead() == i) 
    { 
        pic.Add((byte)headdata.ElementAt(j).getRed());
        pic.Add((byte)headdata.ElementAt(j).getGreen());
        pic.Add((byte)headdata.ElementAt(j).getBlue()); 
    }
}

解决方法

首先,正如我在评论中所说,最好使用List而不是ArrayList来避免装箱/拆箱.

然后,您需要bpp(每像素位数)和宽度和高度来创建图像.

如果你有所有这些值,那么你可以得到起始像素索引:

int i = ((y * Width) + x) * (depth / 8);

例如:

List<byte> bytes = new List<byte>(); // this list should be filled with values
    int width = 100;
    int height = 100;
    int bpp = 24;

    Bitmap bmp = new Bitmap(width,height);

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {   
            int i = ((y * width) + x) * (bpp / 8);
            if(bpp == 24) // in this case you have 3 color values (red,green,blue)
            {
                 // first byte will be red,because you are writing it as first value
                 byte r = bytes[i]; 
                 byte g = bytes[i + 1]; 
                 byte b = bytes[i + 2]; 
                 Color color = Color.FromArgb(r,g,b);
                 bmp.SetPixel(x,y,color); 
            }

        }
    }

您可以使用其他库来更快地创建位图和写入值. (SetPixel()非常慢.See)

相关文章

项目中经常遇到CSV文件的读写需求,其中的难点主要是CSV文件...
简介 本文的初衷是希望帮助那些有其它平台视觉算法开发经验的...
这篇文章主要简单记录一下C#项目的dll文件管理方法,以便后期...
在C#中的使用JSON序列化及反序列化时,推荐使用Json.NET——...
事件总线是对发布-订阅模式的一种实现,是一种集中式事件处理...
通用翻译API的HTTPS 地址为https://fanyi-api.baidu.com/api...