I’m new to c# and I’m sure I’m missing something simple here.
I’m trying to build a bitmap from integer values (0-255) in a double array and then render it in a PictureBox. I think my Bitmap is getting generated but it isn’t displaying in my PictureBox.
Bitmap bmp = new Bitmap(image_width, image_height);
Color pxl_color = new Color();
for (int i = 0; i < image_width; i++)
{
for (int j = 0; j < image_height; j++)
{
pxl_color = Color.FromArgb(array_bitmap[i][j]);
bmp.SetPixel(i, j, pxl_color);
}
}
PictureBox1.Image = bmp;
Thanks in advance.
EDIT:
Changing:
pxl_color=Color.FromArgb(array_bitmap[i][j]);
To:
pxl_color=Color.FromArgb(array_bitmap[i][j],array_bitmap[i][j],array_bitmap[i][j]);
Solves the problem.
Check that you’re not making your image transparent by setting alpha values of the color to zero. The byte-ordering of the 32-bit ARGB value is AARRGGBB. The most significant byte (MSB), represented by AA, is the alpha component value. Make sure the alpha is greater than zero in your color array.
Also try setting the PictureBox sizeMode to AutoSize