【问题标题】:(VB.NET) Rotate Bitmap in Image WPF XAML(VB.NET)在图像 WPF XAML 中旋转位图
【发布时间】:2014-07-28 02:18:53
【问题描述】:

首先,我想澄清一下我是德国人,所以请不要介意我犯的一些语法错误。

我的问题是我想使用 XAML 代码旋转 WPF 中的 Image-Control 中显示的位图:

 <Image Name="ImgDisp"   Grid.ColumnSpan="4" Margin="10,2,10,10" Grid.Row="3" Grid.RowSpan="2"     >
        <Image.Source>
            <TransformedBitmap Source="{Binding Path=CurrentImage}" >
                <TransformedBitmap.Transform>
                    <RotateTransform Angle="90"/>
                </TransformedBitmap.Transform>
            </TransformedBitmap>
        </Image.Source>
 </Image>

属性绑定的类如下所示:

Public Class PropertyClass

    Implements INotifyPropertyChanged
   Public Event PropertyChanged As PropertyChangedEventHandler _
   Implements INotifyPropertyChanged.PropertyChanged

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub




Dim _currentImage As String = ""
Public Property CurrentImage As String
    Get

        Return If(File.Exists(_currentImage), _currentImage, "")

    End Get
    Set(value As String)
        _currentImage = value
        CurrentImageName = New FileInfo(value).Name

        NotifyPropertyChanged("CurrentImage")
    End Set
End Property


Private Shared _instance As PropertyClass
Public Shared ReadOnly Property Instance As PropertyClass
    Get
        If _instance Is Nothing Then _instance = New PropertyClass
        Return _instance
    End Get
End Property

End Class

我得到的错误:

“System.Windows.Markup.XamlParseException”类型的第一次机会异常发生在 >PresentationFramework.dll

附加信息:Zeilennummer "97" und Zeilenposition "42" von "Bei der >Initialisierung von "System.Windows.Media.Imaging.TransformedBitmap" wurde eine Ausnahme >ausgelöst."。

这里有什么问题?非常感谢您的帮助,我对这个问题感到非常恼火。

【问题讨论】:

  • 您需要将其绑定到带有项目中图像的相对路径而不是文件名的字符串。还要确保在您的项目中添加了图像文件,并且该文件的BuildAction 设置为Resource
  • 这样做的问题是用户更改了图像控件中的图像,因此将其放入资源中是不可能的。我用项目中的图像对其进行了测试,它可以工作!问题是如何使用图像的文件路径实现这种行为?

标签: wpf image xaml rotation


【解决方案1】:

为什么要在源上应用旋转变换?而是旋转您的图像控件。

这里是 XAML:

<Image Source="{Binding Path=CurrentImage}" x:Name="ImgDisp"   Grid.ColumnSpan="4" Margin="10,2,10,10" Grid.Row="3" Grid.RowSpan="2">
    <Image.RenderTransform> 
            <RotateTransform Angle="90"/>
    </Image.RenderTransform>
</Image>

【讨论】:

  • 因为我不想旋转 Image 控件。我想打开 Image 控件中显示的 Bitmap。也许正如您从 Windows Photoviewer 中知道的那样,您可以在其中顺时针和逆时针转动图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-11
  • 2013-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-05
  • 1970-01-01
相关资源
最近更新 更多