A simply UI cropping image library for WPF that use adroner layer. Some screenshots:
Interface of sample app
Cropping result image
Cropping result image info
- Load image
- Select cropping area
- Crop and save image
- Can draw/redraw cropping rectangle
- Can move cropping rectangle
- Can resize cropping rectangle
- Shadow area outside of cropping rectangle
- Show current size of cropping rectangle
XAML:
<Grid x:Name="RootGrid" MouseLeftButtonDown="RootGrid_OnMouseLeftButtonDown">
<Canvas x:Name="CanvasPanel"
Grid.Column="1">
<Border Height="{Binding ElementName=CanvasPanel, Path=ActualHeight}" Width="{Binding ElementName=CanvasPanel, Path=ActualWidth}" Background="LightBlue">
<Image x:Name = "SourceImage"
Stretch="Fill"/>
</Border>
</Canvas>
</Grid>
Code Behind:
public CroppingAdorner CroppingAdorner;
private void RootGrid_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
CroppingAdorner.CaptureMouse();
CroppingAdorner.MouseLeftButtonDownEventHandler(sender, e);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(CanvasPanel);
CroppingAdorner = new CroppingAdorner(CanvasPanel);
adornerLayer.Add(CroppingAdorner);
}