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