わかりました、私はこれを試しました:
TransformedBitmap tbm = new TransformedBitmap(myBitmapSource, new RotateTransform(angle));
return tbm;
ただし、これは 90 度の倍数以外の角度では機能しません。
新しい RenderTargetBitmap を使用しようとしました:
var image = new Canvas();
image.Width = myBitmapSource.PixelWidth;
image.Height = myBitmapSource.PixelHeight;
image.Background = new ImageBrush(myBitmapSource);
image.RenderTransform = new RotateTransform(angle);
RenderTargetBitmap rtb = new RenderTargetBitmap(myBitmapSource.PixelWidth, myBitmapSource.PixelHeight, myBitmapSource.DpiX, myBitmapSource.DpiY, myBitmapSource.Format);
rtb.Render(image);
return rtb;
しかし、これは私に与えます:
"The calling thread must be STA, because many UI components require this."
これは、GUI を使用せずにサービスで実行されます。
WPF で (GUI を使用せずに) BitmapSource を任意の角度で回転させる方法に関する実用的なコード サンプルを教えてもらえますか?
アップデート: