How to create 1024x1024 RGB bitmap image of white?

前端 未结 4 1046
时光取名叫无心
时光取名叫无心 2020-12-15 16:11

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,          


        
相关标签:
4条回答
  • 2020-12-15 16:23

    You are assigning a new image to resultImage, thereby overwriting your previous attempt at creating a white image (which should succeed, by the way).

    So just remove the line

    resultImage = new Bitmap(image1.Width, image1.Height, grp);
    
    0 讨论(0)
  • 2020-12-15 16:28

    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;
    }
    
    0 讨论(0)
  • 2020-12-15 16:33

    Another approach,

    Create a unit bitmap

    var b = new Bitmap(1, 1);
    b.SetPixel(0, 0, Color.White);
    

    And scale it

    var result = new Bitmap(b, 1024, 1024);
    
    0 讨论(0)
  • 2020-12-15 16:34

    Graphics.Clear(Color)

    Bitmap bmp = new Bitmap(1024, 1024);
    using (Graphics g = Graphics.FromImage(bmp)){g.Clear(Color.White);}
    
    0 讨论(0)
提交回复
热议问题