Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

It's embarrassing to ask this question but can't find an answer.

I tried this in vain.

Image resultImage = new Bitmap(image1.Width, image1.Height, PixelFormat.Format24bppRgb);

using (Graphics grp = Graphics.FromImage(resultImage)) 
{
    grp.FillRectangle(
        Brushes.White, 0, 0, image1.Width, image1.Height);
    resultImage = new Bitmap(image1.Width, image1.Height, grp);
}

I basically want to fill a 1024x1024 RGB bitmap image with white in C#. How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
265 views
Welcome To Ask or Share your Answers For Others

1 Answer

You almost had it:

private Bitmap DrawFilledRectangle(int x, int y)
{
    Bitmap bmp = new Bitmap(x, y);
    using (Graphics graph = Graphics.FromImage(bmp))
    {
        Rectangle ImageSize = new Rectangle(0,0,x,y);
        graph.FillRectangle(Brushes.White, ImageSize);
    }
    return bmp;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...