问题
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