Skip to content

Commit

Permalink
[add] SelectionSaveToImage for elements
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangSakura committed Jul 30, 2024
1 parent 59fe5d9 commit 9ad44ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ private void BorderStrokeSelectionDelete_Click(object sender, RoutedEventArgs e)
private void BtnStrokeSelectionSaveToImage_Click(object sender, RoutedEventArgs e)
{
StrokeCollection selectedStrokes = inkCanvas.GetSelectedStrokes();
var selectedElements = inkCanvas.GetSelectedElements();

if (selectedStrokes.Count > 0)
if (selectedStrokes.Count > 0 || selectedElements.Count > 0)
{
Rect bounds = selectedStrokes.GetBounds();
foreach (UIElement element in selectedElements)
{
Rect elementBounds = element.RenderTransform.TransformBounds(new Rect(0, 0, element.RenderSize.Width, element.RenderSize.Height));
bounds.Union(elementBounds);
}

double width = bounds.Width + 10;
double height = bounds.Height + 10;
Expand All @@ -107,14 +113,22 @@ private void BtnStrokeSelectionSaveToImage_Click(object sender, RoutedEventArgs
{
stroke.Draw(drawingContext);
}

foreach (UIElement element in selectedElements)
{
VisualBrush vb = new VisualBrush(element);
drawingContext.DrawRectangle(vb, null, new Rect(element.RenderSize));
}
}

renderTarget.Render(drawingVisual);

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "PNG Images|*.png";
saveFileDialog.Title = "Save Selected Ink as PNG";
saveFileDialog.FileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff");
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "PNG Images|*.png",
Title = "Save Selected Ink as PNG",
FileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff")
};

if (saveFileDialog.ShowDialog() == true)
{
Expand Down
4 changes: 2 additions & 2 deletions Ink Canvas/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.0.0.0")]
[assembly: AssemblyFileVersion("5.0.0.0")]
[assembly: AssemblyVersion("4.9.9.9")]
[assembly: AssemblyFileVersion("4.9.9.9")]

0 comments on commit 9ad44ab

Please sign in to comment.