0

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.

0

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

This code worked for me as-is, except I generated random values instead of using array_bitmap. Check and make sure your bitmap object is not being destroyed by GC for some reason (perhaps store it in an instance variable). It may also be a painting issue, where you have to refresh or repaint the picturebox or whole form.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.