Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 6b3235b

Browse files
committed
Input Image Resize & Crop feature
1 parent 7646a91 commit 6b3235b

File tree

7 files changed

+312
-103
lines changed

7 files changed

+312
-103
lines changed

OnnxStack.UI/App.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
2323
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />
2424
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
25+
<converters:BooleanToHiddenConverter x:Key="BooleanToHiddenConverter" />
26+
<converters:InverseBooleanToHiddenConverter x:Key="InverseBooleanToHiddenConverter" />
2527

2628
<ObjectDataProvider x:Key="SchedulerType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
2729
<ObjectDataProvider.MethodParameters>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace OnnxStack.UI.Converters
7+
{
8+
[ValueConversion(typeof(bool), typeof(Visibility))]
9+
public class BooleanToHiddenConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
var boolValue = (bool)value;
14+
return !boolValue ? Visibility.Hidden : Visibility.Visible;
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
return null;
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace OnnxStack.UI.Converters
7+
{
8+
[ValueConversion(typeof(bool), typeof(Visibility))]
9+
public class InverseBooleanToHiddenConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
var boolValue = (bool)value;
14+
return !boolValue ? Visibility.Visible : Visibility.Hidden;
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
return null;
20+
}
21+
}
22+
}

OnnxStack.UI/Dialogs/CropImageDialog.xaml

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,69 @@
99
Name="UI"
1010
Title="Crop Image"
1111
SizeToContent="WidthAndHeight"
12-
WindowStartupLocation="CenterOwner"
13-
MinHeight="500" MinWidth="500">
12+
WindowStartupLocation="CenterScreen"
13+
MinHeight="620" MinWidth="400">
1414
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15">
15+
<DockPanel.Resources>
16+
<SolidColorBrush x:Key="CropFrameBrush" Color="WhiteSmoke" />
17+
</DockPanel.Resources>
1518
<StackPanel DockPanel.Dock="Bottom" >
16-
1719
<DockPanel VerticalAlignment="Bottom">
1820
<StackPanel DockPanel.Dock="Right" VerticalAlignment="Bottom">
19-
<Button Command="{Binding CropCommand}" Content="Crop" Width="100" Height="25"></Button>
21+
<Button Content="Crop" Command="{Binding CropCommand}" Visibility="{Binding IsCropped, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Width="100" Height="25" ></Button>
22+
<Button Content="Reset" Command="{Binding ResetCommand}" Visibility="{Binding IsCropped, Converter={StaticResource BooleanToVisibilityConverter}}" Width="100" Height="25"></Button>
2023
</StackPanel>
21-
2224
<StackPanel >
2325
<TextBlock Text="Image File"/>
2426
<userControls:FilePickerTextBox FileName="{Binding ImageFile, Mode=TwoWay}" IsRequired="True"/>
2527
</StackPanel>
26-
2728
</DockPanel>
28-
2929
<UniformGrid Columns="4" Margin="0,25,0,0">
3030
<TextBlock/>
3131
<TextBlock/>
3232
<Button IsCancel="True" Command="{Binding CancelCommand}" MinWidth="100" Height="30">_Cancel</Button>
33-
<Button IsDefault="True" Command="{Binding OkCommand}" MinWidth="100" Height="30">_Ok</Button>
33+
<Button IsDefault="True" Command="{Binding DoneCommand}" MinWidth="100" Height="30">_Done</Button>
3434
</UniformGrid>
3535
</StackPanel>
36-
37-
<StackPanel>
38-
<Canvas Width="{Binding ImageWidth}" Height="{Binding ImageHeight}" MouseWheel="Canvas_MouseWheel">
39-
<Image Source="{Binding SourceImage}" Width="{Binding ImageWidth}" Height="{Binding ImageHeight}" />
40-
<Rectangle x:Name="CropFrame" Stroke="Gainsboro" StrokeThickness="2" Width="{Binding ZoomWidth}" Height="{Binding ZoomHeight}" Fill="Transparent" MouseLeftButtonUp="Canvas_MouseLeftButtonUp" MouseLeftButtonDown="Canvas_MouseLeftButtonDown" MouseMove="Canvas_MouseMove" />
36+
<Border BorderThickness="2" BorderBrush="Gainsboro" >
37+
<Canvas Width="{Binding ImageWidth}" Height="{Binding ImageHeight}" MouseWheel="CropFrame_MouseWheel">
38+
<Image Source="{Binding SourceImage, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding ImageWidth}" Height="{Binding ImageHeight}" />
39+
<Canvas x:Name="CropFrame" Width="{Binding ZoomWidth}" Height="{Binding ZoomHeight}" Visibility="{Binding IsCropped, Converter={StaticResource InverseBooleanToVisibilityConverter}}" MouseLeftButtonUp="CropFrame_MouseLeftButtonUp" MouseLeftButtonDown="CropFrame_MouseLeftButtonDown" MouseMove="CropFrame_MouseMove" >
40+
<Grid>
41+
<Rectangle Width="{Binding Width, ElementName=CropFrame}" Height="{Binding Height, ElementName=CropFrame}" Stroke="{StaticResource CropFrameBrush}" StrokeThickness="2" Fill="Transparent"/>
42+
<Grid Background="Transparent">
43+
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
44+
<userControls:FontAwesome Icon="&#xf047;" IconStyle="Light" Size="40" Color="{StaticResource CropFrameBrush}"/>
45+
<TextBlock Text="Drag to move" Foreground="{StaticResource CropFrameBrush}" HorizontalAlignment="Center"/>
46+
<TextBlock Text="Mouse wheel to zoom" Foreground="{StaticResource CropFrameBrush}" HorizontalAlignment="Center"/>
47+
</StackPanel>
48+
<Grid.Style>
49+
<Style TargetType="{x:Type Grid}">
50+
<Setter Property="Opacity" Value="0"/>
51+
<Style.Triggers>
52+
<Trigger Property="IsMouseOver" Value="True">
53+
<Trigger.EnterActions>
54+
<BeginStoryboard>
55+
<Storyboard>
56+
<DoubleAnimation Storyboard.TargetProperty="Opacity" To=".7" Duration="0:0:0.3" />
57+
</Storyboard>
58+
</BeginStoryboard>
59+
</Trigger.EnterActions>
60+
<Trigger.ExitActions>
61+
<BeginStoryboard>
62+
<Storyboard>
63+
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.3" />
64+
</Storyboard>
65+
</BeginStoryboard>
66+
</Trigger.ExitActions>
67+
</Trigger>
68+
</Style.Triggers>
69+
</Style>
70+
</Grid.Style>
71+
</Grid>
72+
</Grid>
73+
</Canvas>
4174
</Canvas>
42-
</StackPanel>
75+
</Border>
4376
</DockPanel>
4477
</Window>

0 commit comments

Comments
 (0)