C# 位图图像旋转

C# 位图图像旋转,c#,wpf,observablecollection,bitmapimage,C#,Wpf,Observablecollection,Bitmapimage,在我的ModelView中,我有一个可见的BitMapImage集合,它显示在视图的列表框中。我正在尝试在ObservableCollection中旋转所选图像 在日期模板中定义图像显示方式(作为列表框项),可以使用.RenderTransform属性转换/旋转控件 按钮示例: <Button <Button.RenderTransform> <RotateTransform CenterX="0" CenterY=

在我的ModelView中,我有一个可见的BitMapImage集合,它显示在视图的列表框中。我正在尝试在ObservableCollection中旋转所选图像

在日期模板中定义图像显示方式(作为列表框项),可以使用
.RenderTransform
属性转换/旋转控件

按钮示例:

<Button
            <Button.RenderTransform>
                <RotateTransform CenterX="0" CenterY="0" Angle="45"/>
            </Button.RenderTransform>
            Test</Button>

在日期模板中定义图像的显示方式(作为列表框项),可以使用
.RenderTransform
属性转换/旋转控件

按钮示例:

<Button
            <Button.RenderTransform>
                <RotateTransform CenterX="0" CenterY="0" Angle="45"/>
            </Button.RenderTransform>
            Test</Button>

好的,想好了,如果有什么事情看起来很愚蠢,你可以告诉我

//Create a transform
TransformedBitmap tBmp = new TransformedBitmap();
tBmp.BeginInit();

//Set the source = to the image currently selected
tBmp.Source = _Scans[_selectedImage].MyImage;
RotateTransform rt = new RotateTransform(180);
tBmp.Transform = rt;
tBmp.EndInit();

//Create a new source after the transform
BitmapSource s1 = tBmp;
BitmapImage bi = BitmapSourceToBitmapImage(s1);

//Add create the item and replace the current item in the collection
//edited according to comment
//ScannedImages s = new ScannedImages();
//s.MyImage = bi;
//_Scans[_selectedImage] = s;
Scans[_selectedImage].MyImage = BitmapSourceToBitmapImage(s1);

好吧,想清楚了,如果有什么事情看起来很愚蠢,你可以告诉我

//Create a transform
TransformedBitmap tBmp = new TransformedBitmap();
tBmp.BeginInit();

//Set the source = to the image currently selected
tBmp.Source = _Scans[_selectedImage].MyImage;
RotateTransform rt = new RotateTransform(180);
tBmp.Transform = rt;
tBmp.EndInit();

//Create a new source after the transform
BitmapSource s1 = tBmp;
BitmapImage bi = BitmapSourceToBitmapImage(s1);

//Add create the item and replace the current item in the collection
//edited according to comment
//ScannedImages s = new ScannedImages();
//s.MyImage = bi;
//_Scans[_selectedImage] = s;
Scans[_selectedImage].MyImage = BitmapSourceToBitmapImage(s1);

有没有一种方法可以直接在modelView中的Observable集合中执行此操作,因为我不想旋转所有图像,只旋转选定的图像?您不必旋转所有图像,将DataTemplate与列表框一起使用,它会为您旋转图像。否则,您必须在WPF外部操作图像,并以“旋转状态”将其添加到集合中,这正是我想要的,因为如果图像旋转,我需要以相同的方式将其保存回XPS文件中。我也只有一个旋转按钮,我没有把它放在列表框中。如果你没有使用DataTemplate,那么你可以对你的图像使用样式,这样所有的图像都可以在初始化时旋转。没有使用XPS,不知道打印/保存过程如何工作有没有办法直接在modelView中的可观察集合中执行此操作,因为我不想旋转所有图像,只旋转选定的图像?您不必旋转所有图像,使用DataTemplate和列表框,它会为您旋转图像。否则,您必须在WPF外部操作图像,并以“旋转状态”将其添加到集合中,这正是我想要的,因为如果图像旋转,我需要以相同的方式将其保存回XPS文件中。我也只有一个旋转按钮,我没有把它放在列表框中。如果你没有使用DataTemplate,那么你可以对你的图像使用样式,这样所有的图像都可以在初始化时旋转。使用XPS的效果不太好,不确定打印/保存过程如何工作确定,划掉我制作新项目的最后一部分并将其添加到集合中。我对WPF和数据绑定相当陌生,忘记将NotifyPropertyChanged放在集合中的项目上。所以最后4行代码应该是这一行。扫描[\u selectedImage].MyImage=BitmapSourceToBitmapImage(s1);好的,抓取最后一部分,在那里我创建了一个新项目,并将其添加到集合中。我对WPF和数据绑定相当陌生,忘记将NotifyPropertyChanged放在集合中的项目上。所以最后4行代码应该是这一行。扫描[\u selectedImage].MyImage=BitmapSourceToBitmapImage(s1);