c# – 像素数据到图像

c# – 像素数据到图像,第1张

概述我有这种格式的列表像素 ArrayList list = new ArrayList();list.add(Red);list.add(Blue);list.add(Green); 我有很多像这样的价值观.我想将数组列表转换为图像..尝试了很多,但没有找到任何适当的材料. 编辑:这可能有所帮助: List<byte> pic = new List<byte>(); for (int j = 我有这种格式的列表像素
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)

总结

以上是内存溢出为你收集整理的c# – 像素数据到图像全部内容,希望文章能够帮你解决c# – 像素数据到图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1235847.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存