开发者

BitmapImage Rotation

In my ModelView I have an ObservableCollection of BitmapImages that displays in a listbox on my view. I am trying to rota开发者_JS百科te the selected image in the ObservableCollection.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜