补充图像旋转和放大wpf

时间:2015-01-26 12:16:25

标签: c# wpf mvvm-light

我想制作一个图像查看器,它可以显示带旋转功能的图像,并使用滑块放大和缩小,但现在我不知道旋转和缩放,请帮助,xaml代码:

        <Viewbox>
        <Image Source="{Binding JpgImageSource}">
        </Image>
        </Viewbox>
    <StackPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Width="100">
        <Button Content="open" Width="80" Margin="5" Command="{Binding OpenJpgImgCmd}"/>
        <Button Content="leftrotate90" Width="80" Margin="5" Command="{Binding LeftRotate90Cmd}"></Button>
        <Button Content="rightrotate90" Width="80" Command="{Binding}"/>
        <Slider Orientation="Vertical" Height="100" Margin="5" HorizontalAlignment="Center"/>

后面的代码如下,我已经改变了bitmapsource的路径,现在如何补充rotate命令和缩放命令

            OpenFileDialog ofdimg=new OpenFileDialog();
            ofdimg.Filter = "Image Files (*.jpg;*.jpep)|*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.gif;|All Files (*.*)|*.*";
            ofdimg.ShowDialog();
            string ImgPath = ofdimg.FileName;
            BitmapSource bm = new BitmapImage(new Uri(ImgPath));
            JpgImageSource = bm;

1 个答案:

答案 0 :(得分:3)

图像控件不知道如何解析图像。您应该将它绑定到BitmapSource。 在查询图像的路径后,只需执行BitmapSource source = new BitmapImage(new Uri(path));并将Image控件绑定到BitmapSource。

相关问题