我有一个 mvvm 项目。我通过单击项目中的加载按钮加载 .jpg 格式的图像。我想选择该图像的一部分并移动它并通过单击菜单中的矩形工具重新调整它的大小,但我不知道如何
查看代码:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="240*" />
<RowDefinition Height="60*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Image Source="{Binding MyImage.Source}" ></Image>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Width="70" Height="40" Command="{Binding LoadCommand}">Load Image</Button>
</StackPanel>
</Grid>
视图模型代码:
#region Property
private Image _MyImage;
public Image MyImage
{
get
{
return _MyImage;
}
set
{
_MyImage = value;
OnPropertyChanged("MyImage");
}
}
#endregion
#region Constructor
public ImageViewModel()
{
_MyImage = new Image();
}
#endregion
#region Commands
RelayCommand _LoadCommand;
public ICommand LoadCommand
{
get
{
if (_LoadCommand == null)
{
_LoadCommand = new RelayCommand(param => LoadCommandExecute());
}
return _LoadCommand;
}
}
#endregion
#region Methods
private void LoadCommandExecute()
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "Select a picture";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (op.ShowDialog() == true)
{
MyImage.Source = new BitmapImage(new Uri(op.FileName));
}
}
#endregion