|
@@ -165,6 +165,12 @@ public partial class ImageEditor : UserControl
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region Events
|
|
|
+
|
|
|
+ public event EventHandler? Changed;
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region Private Properties
|
|
|
|
|
|
public ObservableCollection<ImageEditorModeButton> ModeButtons { get; set; } = new();
|
|
@@ -260,6 +266,7 @@ public partial class ImageEditor : UserControl
|
|
|
RedoStack.Push(Objects[^1]);
|
|
|
Objects.RemoveAt(Objects.Count - 1);
|
|
|
UpdateUndoRedoButtons();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
@@ -269,6 +276,7 @@ public partial class ImageEditor : UserControl
|
|
|
|
|
|
Objects.Add(top);
|
|
|
UpdateUndoRedoButtons();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
}
|
|
|
|
|
|
private void AddObject(IImageEditorObject obj)
|
|
@@ -276,6 +284,7 @@ public partial class ImageEditor : UserControl
|
|
|
Objects.Add(obj);
|
|
|
RedoStack.Clear();
|
|
|
UpdateUndoRedoButtons();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
@@ -410,9 +419,10 @@ public partial class ImageEditor : UserControl
|
|
|
Objects.Clear();
|
|
|
RedoStack.Clear();
|
|
|
UpdateUndoRedoButtons();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
}
|
|
|
|
|
|
- public Bitmap? GetImage()
|
|
|
+ public Bitmap GetImage()
|
|
|
{
|
|
|
var renderBitmap = new RenderTargetBitmap(new PixelSize(ImageWidth, ImageHeight));
|
|
|
renderBitmap.Render(Image);
|
|
@@ -437,6 +447,15 @@ public partial class ImageEditor : UserControl
|
|
|
return renderBitmap;
|
|
|
}
|
|
|
|
|
|
+ public byte[] SaveImage()
|
|
|
+ {
|
|
|
+ var bitmap = GetImage();
|
|
|
+
|
|
|
+ var stream = new MemoryStream();
|
|
|
+ bitmap.Save(stream);
|
|
|
+ return stream.ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region Editing
|
|
@@ -503,14 +522,17 @@ public partial class ImageEditor : UserControl
|
|
|
case PolylineObject polyline:
|
|
|
polyline.Points.Add(position);
|
|
|
polyline.Update();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
break;
|
|
|
case RectangleObject rectangle:
|
|
|
rectangle.Point2 = position;
|
|
|
rectangle.Update();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
break;
|
|
|
case EllipseObject ellipse:
|
|
|
ellipse.Point2 = position;
|
|
|
ellipse.Update();
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -524,16 +546,19 @@ public partial class ImageEditor : UserControl
|
|
|
polyline.Points.Add(position);
|
|
|
polyline.Update();
|
|
|
CurrentObject = null;
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
break;
|
|
|
case RectangleObject rectangle:
|
|
|
rectangle.Point2 = position;
|
|
|
rectangle.Update();
|
|
|
CurrentObject = null;
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
break;
|
|
|
case EllipseObject ellipse:
|
|
|
ellipse.Point2 = position;
|
|
|
ellipse.Update();
|
|
|
CurrentObject = null;
|
|
|
+ Changed?.Invoke(this, new EventArgs());
|
|
|
break;
|
|
|
}
|
|
|
|