1
Reply

Create Blank White Bitmap Image

David Galea

David Galea

Feb 19 2009 6:24 AM
26k
hey guys,

I have a Form with a Picture Box, whereby upon loading of the form the Image in the Picture Box is a White Bitmap Image,

I have been using a Brute force Method so far being
Bitmap B = new Bitmap(row,columns);
for(int i = 1 ; i <= row ; i++)
    for(int j = 1 ; j<= columns ; j ++)
        B.SetPixel(i,j,Color.White)
this.mypicturebox.Image = B;

This works but is time computationally inefficient and I read somewhere you can use the Graphics Class to make the job easier, I tried the following
Bitmap B = new Bitmap(row,columns);
Graphics G = Graphics.FromImage(B);
G.FillRectangle(Brushes.White,0,0,row,columns);
this.mypicturebox.Image = new Bitmap(row,columns,G)

However it does work, furthermore upon compilation it states that the local variable G is declared but not used ???

What am I doing wrong??

Thanks in advance,

David

Answers (1)