Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Created November 10, 2018 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/5bfb63fbe5573d06d780366b7c6e2ebc to your computer and use it in GitHub Desktop.
Save gdyrrahitis/5bfb63fbe5573d06d780366b7c6e2ebc to your computer and use it in GitHub Desktop.
public void Draw()
{
// Save state
SavePreviousState();
// Carry out the command execution
var brush = new SolidBrush(_color);
var rectangle = new System.Drawing.Rectangle(_point.X, _point.Y, Width, Height);
_graphics.FillRectangle(brush, rectangle);
}
// Saving all pixels in the area we are going to draw
// We are storing the color of each pixel
// When we perform an undo, all pixels will be restored to initial state
private void SavePreviousState()
{
for (int i = _point.X; i < _point.X + Width; i++)
{
for (int j = _point.Y; j < _point.Y + Height; j++)
{
_previousState.Add(_bitmap.GetPixel(i, j));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment