|
@@ -1,6 +1,10 @@
|
|
|
|
|
+using System;
|
|
|
|
|
+using Avalonia;
|
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls;
|
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Markup.Xaml;
|
|
|
using Avalonia.Media;
|
|
using Avalonia.Media;
|
|
|
|
|
+using Avalonia.Media.Imaging;
|
|
|
|
|
+using Avalonia.Platform;
|
|
|
|
|
|
|
|
namespace ControlCatalog.Pages
|
|
namespace ControlCatalog.Pages
|
|
|
{
|
|
{
|
|
@@ -8,12 +12,14 @@ namespace ControlCatalog.Pages
|
|
|
{
|
|
{
|
|
|
private readonly Image _bitmapImage;
|
|
private readonly Image _bitmapImage;
|
|
|
private readonly Image _drawingImage;
|
|
private readonly Image _drawingImage;
|
|
|
|
|
+ private readonly Image _croppedImage;
|
|
|
|
|
|
|
|
public ImagePage()
|
|
public ImagePage()
|
|
|
{
|
|
{
|
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
|
_bitmapImage = this.FindControl<Image>("bitmapImage");
|
|
_bitmapImage = this.FindControl<Image>("bitmapImage");
|
|
|
_drawingImage = this.FindControl<Image>("drawingImage");
|
|
_drawingImage = this.FindControl<Image>("drawingImage");
|
|
|
|
|
+ _croppedImage = this.FindControl<Image>("croppedImage");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void InitializeComponent()
|
|
private void InitializeComponent()
|
|
@@ -38,5 +44,32 @@ namespace ControlCatalog.Pages
|
|
|
_drawingImage.Stretch = (Stretch)comboxBox.SelectedIndex;
|
|
_drawingImage.Stretch = (Stretch)comboxBox.SelectedIndex;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void BitmapCropChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_croppedImage != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ var comboxBox = (ComboBox)sender;
|
|
|
|
|
+ var croppedBitmap = _croppedImage.Source as CroppedBitmap;
|
|
|
|
|
+ croppedBitmap.SourceRect = GetCropRect(comboxBox.SelectedIndex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private PixelRect GetCropRect(int index)
|
|
|
|
|
+ {
|
|
|
|
|
+ var bitmapWidth = 640;
|
|
|
|
|
+ var bitmapHeight = 426;
|
|
|
|
|
+ var cropSize = new PixelSize(320, 240);
|
|
|
|
|
+ return index switch
|
|
|
|
|
+ {
|
|
|
|
|
+ 1 => new PixelRect(new PixelPoint((bitmapWidth - cropSize.Width) / 2, (bitmapHeight - cropSize.Width) / 2), cropSize),
|
|
|
|
|
+ 2 => new PixelRect(new PixelPoint(0, 0), cropSize),
|
|
|
|
|
+ 3 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, 0), cropSize),
|
|
|
|
|
+ 4 => new PixelRect(new PixelPoint(0, bitmapHeight - cropSize.Height), cropSize),
|
|
|
|
|
+ 5 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, bitmapHeight - cropSize.Height), cropSize),
|
|
|
|
|
+ _ => PixelRect.Empty
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|