Display double array in picturebox

落爺英雄遲暮 提交于 2019-12-11 19:19:36

问题


I need to display this array of double in picture box in C#

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;

I use this code for display but not work is there other method for display array of double(Brightness) in picture box (bmp file)


回答1:


You can't cast directly from integer to color. Using Color.FromArgb() allows you to specify an integer value for color.

FromArgb() takes a 32 bit integer where each byte represents one of Alpha, Red, Green, Blue (hence Argb). Keep in mind that if you want any pixel with more than half opacity (Alpha) value, your passed integer will need to be a negative value.

If you don't have any negative values in your Y1 array, you will want to apply the following when doing the FromArgb() conversion.

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

Hope that helps.



来源:https://stackoverflow.com/questions/20974290/display-double-array-in-picturebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!