Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This is a basic workflow to help you get started with Actions

name: CI


# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:

# The type of runner that the job will run on
runs-on: windows-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2


- name: setup-msbuild
uses: microsoft/setup-msbuild@v1

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.2

- name: Navigate to Workspace
run: cd $GITHUB_WORKSPACE

- name: Create Build Directory
run: mkdir _build

- name: Restore Packages
run: nuget restore UI-Cropping-Image-Library/UI-Cropping-Image-Library.sln

- name: Build Solution
run: |
msbuild.exe UI-Cropping-Image-Library/UI-Cropping-Image-Library.sln /p:platform="Any CPU" /p:configuration="Release"

- name: Upload artifact
uses: actions/upload-artifact@v1.0.0
with:
name: EZRepBundle
path: "./UI-Cropping-Image-Library/CroppingImageLibrary.SampleApp/bin/Release/"

- name: Nuget Pack
run: nuget pack ./UI-Cropping-Image-Library/CroppingImageLibrary/CroppingImageLibrary.csproj -Properties Configuration=Release

- name: Nuget Push
run: nuget push CroppingImageLibrary.1.0.1.nupkg ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json

- name: Show Content
run: dir

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# UI-Cropping-Image
A simply UI cropping image library for WPF that use adroner layer. Some screenshots:

### Installing

To install CroppingImageLibrary just execute the following command in your nuget CLI :

```bash
Install-Package CroppingImageLibrary -Version 1.0.1
```

Interface of sample app

<img src="https://github.com/dmitryshelamov/UI-Cropping-Image/blob/master/cropped-demo.png" width="400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
xmlns:croppingImageLibrary="clr-namespace:CroppingImageLibrary;assembly=CroppingImageLibrary"
mc:Ignorable="d"
Title="CroppingWindow" ResizeMode="NoResize" WindowStartupLocation="Manual" SizeToContent ="WidthAndHeight">
<croppingImageLibrary:CropToolControl Name="CropTool"></croppingImageLibrary:CropToolControl>
<croppingImageLibrary:CropToolControl Name="CropTool" SquareSelection="True" ></croppingImageLibrary:CropToolControl>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public MainWindow()
{
InitializeComponent();
Topmost = true;

}

private void Button_LoadImage(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -14,6 +15,20 @@ public partial class CropToolControl : UserControl
{
public CropService CropService { get; private set; }





private bool squareSelection = false;
[Description("Whether to force the user to select only square or not"), Category("Data")]
public bool SquareSelection
{
get { return squareSelection; }
set { squareSelection = value; }
}



public CropToolControl()
{
InitializeComponent();
Expand All @@ -31,7 +46,7 @@ private void RootGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

private void RootGrid_Loaded(object sender, RoutedEventArgs e)
{
CropService = new CropService(this);
CropService = new CropService(this , SquareSelection);
}

public void SetImage(BitmapImage bitmapImage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CroppingImageLibrary</RootNamespace>
<AssemblyName>CroppingImageLibrary</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>8</LangVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CroppingImageLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("The user control for cropping images in WPF")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Apex")]
[assembly: AssemblyProduct("CroppingImageLibrary")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -31,5 +31,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("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class CropService
private readonly IToolState _dragState;
private readonly IToolState _completeState;

//Hack: added by sinathr
private readonly bool _squareSelection;

public Adorner Adorner => _cropAdorner;

private enum TouchPoint
Expand All @@ -41,8 +44,11 @@ private enum TouchPoint
InsideRectangle
}

public CropService(FrameworkElement adornedElement)
public CropService(FrameworkElement adornedElement , bool squareSelection)
{
//Hack: added by thr
_squareSelection = squareSelection;

_canvas = new Canvas
{
Height = adornedElement.ActualHeight,
Expand All @@ -67,7 +73,7 @@ public CropService(FrameworkElement adornedElement)
StrokeDashArray = new DoubleCollection(new double[] { 4, 4 })
}
);
_cropTool = new CropTool(_canvas);
_cropTool = new CropTool(_canvas , _squareSelection);
_createState = new CreateState(_cropTool, _canvas);
_completeState = new CompleteState();
_dragState = new DragState(_cropTool, _canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ internal class CropShape
{
public Shape Shape { get; }
public Shape DashedShape { get; }
private readonly Canvas _originalCanvas;
private readonly bool _squareSelection;

public CropShape(Shape shape, Shape dashedShape)
public CropShape(Shape shape, Shape dashedShape, bool squareSelection = false , Canvas overlayCanvas= null)
{
Shape = shape;
DashedShape = dashedShape;
_originalCanvas = overlayCanvas;
_squareSelection = squareSelection;
}

public void Redraw(double newX, double newY, double newWidth, double newHeight)
{
//dont use negative value
if (newHeight >= 0 && newWidth >= 0)
{
RedrawSolidShape(newX, newY, newWidth, newHeight);
if(_squareSelection)
UpdateRectangle(newX, newY, newWidth, newHeight);
else
RedrawSolidShape(newX, newY, newWidth, newHeight);
//
RedrawDashedShape();
}
}
Expand All @@ -39,5 +47,33 @@ private void RedrawDashedShape()
Canvas.SetLeft(DashedShape, Canvas.GetLeft(Shape));
Canvas.SetTop(DashedShape, Canvas.GetTop(Shape));
}


public void UpdateRectangle(double newX, double newY, double newWidth, double newHeight)
{
//dont use negative value
if (newHeight >= 0 && newWidth >= 0)
{
Canvas.SetLeft(Shape, newX);
Canvas.SetTop(Shape, newY);
Shape.Height = newHeight;
Shape.Width = newHeight;

if (Shape.Height > _originalCanvas.ActualWidth)
{
Canvas.SetLeft(Shape, 0);
Shape.Height = _originalCanvas.ActualWidth;
Shape.Width = _originalCanvas.ActualWidth;
}

if (Shape.Height + newX > _originalCanvas.ActualWidth)
{
Canvas.SetLeft(Shape, _originalCanvas.ActualWidth - Shape.ActualWidth);
}
//we need to update dashed rectangle too
// UpdateDashedRectangle();
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal class CropTool
private readonly ShadeTool _shadeService;
private readonly ThumbTool _thumbService;
private readonly TextTool _textService;



public double TopLeftX => Canvas.GetLeft(_cropShape.Shape);
public double TopLeftY => Canvas.GetTop(_cropShape.Shape);
Expand All @@ -19,8 +21,9 @@ internal class CropTool
public double Height => _cropShape.Shape.Height;
public double Width => _cropShape.Shape.Width;

public CropTool(Canvas canvas)
public CropTool(Canvas canvas , bool squareSelection = false)
{

_canvas = canvas;
_cropShape = new CropShape(new Rectangle {
Height = 0,
Expand All @@ -31,7 +34,7 @@ public CropTool(Canvas canvas)
new Rectangle {
Stroke = Brushes.White,
StrokeDashArray = new DoubleCollection(new double[] { 4, 4 })
});
} , squareSelection , _canvas);

_shadeService = new ShadeTool(canvas, this);
_thumbService = new ThumbTool(canvas, this);
Expand Down