2011-07-06 12 views
1

私のModelViewには、ObservableCollection of BitmapImagesがあり、私のビューのリストボックスに表示されます。 ObservableCollectionで選択したイメージを回転しようとしています。BitmapImage Rotation

+0

愚かに見え、あなたの質問があるなら、私に知らせることができます... – anivas

答えて

0

Imageを(ListBox Itemとして)表示する方法を定義するDateTemplateでは、.RenderTransformプロパティを使用してコントロールを変形/回転できます。

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

されていますモデルビューのObservable Collectionでこれを直接行う方法があります。選択した画像だけをすべて回転させたくないのですから? –

+0

あなたは、すべての画像を回転させる必要はありません、あなたのリストボックスでDataTemplateを使用すると、それらがあなたのために回転します。それ以外の場合は、WPFの外で画像を操作して、「回転状態」のコレクションに追加する必要があります –

+0

画像が回転した場合、XPSファイルに同じ方法で保存する必要があります。私はまた、1つの回転ボタンを持っていた、私はリストボックスに入れていない。 –

1

[OK]を、それを考え出した、あなたは何かが

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

OK、新しいアイテムを作成した最後の部分をスクラッチしてコレクションに追加します。私はかなりWPFとデータバインディングを新しくしており、コレクション内のアイテムにNotifyPropertyChangedを配置するのを忘れていました。したがって、コードの最後の4行はこの行にする必要があります。スキャン[_selectedImage] .MyImage = BitmapSourceToBitmapImage(s1); –