Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this code to create a image in bitmap.
The below code sets the entire bitmap into white image.

C#
for (i = 0; i < Height; i++)
               for (j = 0; j < Width; j++)
                   BufferImage.SetPixel(j, i, Color.White);


Is what I am thinking is correct?

C#
void DrawingPanel1_Paint(object Sender, PaintEventArgs e)
       {
           Graphics g = e.Graphics;
           g.DrawImage(BufferImage,0,0);
       }


Why this code is used?
In my application this function is getting called every time when my controls are refreshed. What will in e, when it is called?

what does these do
e.Graphics
g.DrawImage(BufferImage,0,0)
Posted
Updated 14-Oct-10 21:27pm
v2
Comments
Dalek Dave 15-Oct-10 3:27am    
Edited for Readability.

1 solution

You really should do a little reading for yourself.

You seem to want to know what a Graphics object is and what it does. So take a look at the documentation here[^].

Put very simply a Graphics is a class that enables you to draw on a Bitmap or Control.

Your first code sample should work but will be comparatively slow. If possible you should replace it with something like

C#
using (Graphics g = Graphics.FromImage(BufferImage))
{
  g.Clear(Colors.White);
}


which will be far quicker.

The e.Graphics in the second snippet is a Graphics object that will do all its drawing on DrawingPanel1 whatever sort of control that is (I assume a Panel)

For DrawImage, why not read it for yourself from the link I gave you earlier? You will learn far more that way.
 
Share this answer
 
Comments
swathi6589 15-Oct-10 6:17am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900