0

わかりました、私はこれを試しました:

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 を任意の角度で回転させる方法に関する実用的なコード サンプルを教えてもらえますか?

アップデート:

機能リクエストの投票: http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10870098-allow-rotation-of-bitmapsource-by-any-angle

4

3 に答える 3