Tuesday, August 4, 2009

Creating and Saving a Picture

There are 3 steps to creating and saving a picture:
  1. Create a Bitmap object.
  2. Edit it using Graphics object.
  3. Call Bitmap.Save method to save it.

Code Example:
Bitmap bm = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bm);
g.DrawEllipse(new Pen(Color.Red), new Rectangle(5, 5, 90, 90));
bm.Save("bm.jpg", ImageFormat.Jpeg);
Here is what it looks like:
If you would like to edit an existing image instead, you can use:
Bitmap bm = new Bitmap("existingImage.jpg");

More Info: MSDN: Bitmap Class