2011-02-04 7 views
7

私はRenderTargetBitmapに数十のビジュアルをレンダリングしています。それぞれはそれ自身のRectにレンダリングされます。 私がしたいのは、RenderTargetBitmapインスタンスからレンダリングされたこれらのRect領域の1つをWriteableBitmapの同じ領域にコピーすることです...高速コピーのrectピクセルまたはsmth。そうですね。RenderTargetBitmapからWriteableBitmapにビットブライトする方法は?

RenderTargetBitmapからWriteableBitmapにrectを高速でコピーする方法はありますか?

ありがとうございます。

このようWriteableBitmapする全体RenderTargetBitmapをコピーすることによって解決

答えて

3

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)); 
} 
関連する問題