【问题标题】:Display double array in picturebox在图片框中显示双数组
【发布时间】:2014-01-07 14:33:28
【问题描述】:

我需要在 C# 的图片框中显示这个 double 数组

double[,] Y1 = new double[width, height];//not empty array contain brightness from RGB
 R = new byte [width, height];
 G = new byte [width, height];
 B = new byte [width, height];

Bitmap bmp4 = new Bitmap(width, height);    


for (int x = 0; x < width; x++)
{
    for (int y = 0; y < height; y++)
    {
        Y1[x, y] = (0.39 * R[x,y]) + (0.59 * G[x,y]) + (0.12 * B[x,y]);
        Int32 zz = Convert.ToInt32(Y1[x, y]);

        bmp4.SetPixel(x, y, zz);
    }
}    

pictureBox6.Image=bmp4;

我使用此代码进行显示但不起作用是否有其他显示数组的方法 double(Brightness)在图片框中(bmp文件)

【问题讨论】:

  • @Brandon,无法在“colors[x,y]=(Color)zz;”中将整数转换为颜色
  • 使用 Color.FromArgb(zz);
  • @Brandon,我使用 Color.FromArgb(zz) 但图片不显示,为什么?
  • 我要输入一个答案,因为我已经弄清楚你想要做什么......等等。

标签: c# bitmap rgb picturebox brightness


【解决方案1】:

您不能直接从整数转换为颜色。使用Color.FromArgb() 可以为颜色指定一个整数值。

FromArgb() 采用 32 位整数,其中每个字节代表 Alpha、Red、Green、Blue 之一(因此 Argb)。请记住,如果您希望任何像素具有超过一半的不透明度 (Alpha) 值,则您传递的整数需要为负值。

如果您的 Y1 数组中没有任何负值,您将需要在进行 FromArgb() 转换时应用以下内容。

colors[x,y]= Color.FromArgb(zz | (255 &lt;&lt; 24))

希望对您有所帮助。

【讨论】:

  • ,谢谢你的帮助,我写“colors[x,y]= Color.FromArgb(zz | (255
  • 自从我回答以来,您已经更改了问题,并且根据您评论中的信息,我现在不知道您要做什么。
猜你喜欢
  • 1970-01-01
  • 2012-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 2018-03-15
相关资源
最近更新 更多