swetha
swetha

Reputation: 1

Image class in C#

Can anyone help me out in setting blank image using Image class in C#? I mean, i have few images to be displayed based on some manipulations.If any condition is met, i shouldn't display any image in tat case.And i dont hav any default image to display for the above said scenario.How can i implement this?

Upvotes: 0

Views: 930

Answers (1)

Oded
Oded

Reputation: 499002

Like this?

Image blank = new Bitmap(width, height);

This will produce a new image with the specified width and height (integers).

If you want the image to have a specific color, you will need to set each pixel with SetPixel:

// Set each pixel in blank to black. Use a different Color.xxx if you wish
for (int Xcount = 0; Xcount < myBblankitmap.Width; Xcount++)
{
    for (int Ycount = 0; Ycount < blank.Height; Ycount++)
    {
        blank.SetPixel(Xcount, Ycount, Color.Black);
    }
}

Alternatively, you can create an actual default image (using an image editor of your choice) and display that.

Upvotes: 1

Related Questions