void DrawTest(Bitmap image)
{
// should always ensure .Dispose() is called when you are done with a Graphics or BitmapData object.
// Test setting pixels directly
using (var bd = image.Lock())
{
var sz = image.Size / 5;
for (int x = sz.Width; x < sz.Width * 2; x++)
for (int y = sz.Height; y < sz.Height * 2; y++)
bd.SetPixel(x, y, Colors.Green);
}
// Test using Graphics object
using (var graphics = new Graphics(image))
{
graphics.DrawLine(Pens.Blue, Point.Empty, new Point(image.Size));
graphics.DrawRectangle(Pens.Blue, new Rectangle(image.Size - 1));
}
// should be able to set pixels after using graphics object
using (var bd = image.Lock())
{
var sz = image.Size / 5;
for (int x = sz.Width * 3; x < sz.Width * 4; x++)
for (int y = sz.Height * 3; y < sz.Height * 4; y++)
bd.SetPixel(x, y, Colors.Red);
}
}