Skip to content
WPF visual cropping image library
C#
Branch: master
Clone or download
dmitryshelamov Update Readme
Add screenshots
Latest commit 5d4437a Jan 8, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
UI-Cropping-Image-Library Add first version of library Jan 8, 2018
.gitignore Initial commit Jan 7, 2018
LICENSE Initial commit Jan 7, 2018
README.md Update Readme Jan 8, 2018
cropped-demo.png Add demonstated images Jan 8, 2018
cropped-result-info.png Add demonstated images Jan 8, 2018
cropped-result.png Add demonstated images Jan 8, 2018

README.md

UI-Cropping-Image

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

Main Workflow:

  1. Load image
  2. Select cropping area
  3. Crop and save image

Main features:

  • 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

Basic Setup

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);
    }
You can’t perform that action at this time.