我正在向RenderTargetBitmap渲染几十个视觉效果。每一个都在它自己的Rect中呈现。我想要做的是将其中一个从RenderTargetBitmap实例渲染的矩形区域复制到WriteableBitmap...Fast复制矩形像素或smth的相同区域中。就像这样。
那么,有没有一种方法可以快速地将rect从RenderTargetBitmap复制到WriteableBitmap呢?
发布于 2011-02-08 13:10:31
通过将整个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));
}https://stackoverflow.com/questions/4901272
复制相似问题