位图图像旋转

发布于 2024-11-18 15:42:04 字数 115 浏览 5 评论 0原文

在我的 ModelView 中,我有一个 BitmapImages 的 ObservableCollection,它显示在我的视图上的列表框中。我正在尝试旋转 ObservableCollection 中选定的图像。

In my ModelView I have an ObservableCollection of BitmapImages that displays in a listbox on my view. I am trying to rotate the selected image in the ObservableCollection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2024-11-25 15:42:04

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

//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);

Ok, figured it out and you can let me know if something looks stupid

//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);
一身仙ぐ女味 2024-11-25 15:42:04

在您定义如何显示图像(作为列表框项)的 DateTemplate 中,您可以使用 .RenderTransform 属性来转换/旋转您的控件。

按钮示例:

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

了解有关如何旋转对象的更多信息? MSDN 文章

In your DateTemplate where you define how you would like to display your Image (as ListBox Item), you can use .RenderTransform property to transform/rotate your Control.

Example for Button:

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

Have a read more on How to Rotate an object? MSDN Article

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文