7

RenderTargetBitmap に多数のビジュアルをレンダリングしています。それぞれが独自の Rect でレンダリングされます。私がやりたいことは、RenderTargetBitmap インスタンスからレンダリングされたこれらの Rect 領域の 1 つを WriteableBitmap の同じ領域にコピーすることです...高速コピー rect ピクセルまたはスムス。そのように。

では、rect を RenderTargetBitmap から WriteableBitmap にすばやくコピーする方法はありますか?

4

1 に答える 1

4

次のように RenderTargetBitmap 全体を WriteableBitmap にコピーすることで解決しました。

 protected override void OnRender(DrawingContext drawingContext)
 {
   if (ActualWidth == 0 || ActualHeight == 0) return;
   // Create destination bitmap
   wb = new WriteableBitmap((int) ActualWidth, (int) ActualHeight, 96, 96, PixelFormats.Pbgra32, null);
   wb.Lock();
   rtb = new RenderTargetBitmap(wb.PixelWidth, wb.PixelHeight, wb.DpiX, wb.DpiY, PixelFormats.Pbgra32);
   foreach (MyVisual visual in visuals)
   {
     visual.Render(rtb);
   }

   rtb.CopyPixels(new Int32Rect(0,0, rtb.PixelWidth, rtb.PixelHeight), 
   wb.BackBuffer,
   wb.BackBufferStride * wb.PixelHeight,  wb.BackBufferStride);

   wb.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
   wb.Unlock();

   drawingContext.DrawImage(wb, new Rect(0, 0, ActualWidth, ActualHeight));
}
于 2011-02-08T05:10:30.937 に答える