gpt4 book ai didi

wpf - 如何从 RenderTargetBitmap bitblit 到 WriteableBitmap?

转载 作者:行者123 更新时间:2023-12-04 12:43:23 33 4
gpt4 key购买 nike

我正在向 RenderTargetBitmap 渲染数十种视觉效果。每个都在它自己的 Rect 中呈现。
我想要做的是将从 RenderTargetBitmap 实例呈现的这些 Rect 区域之一复制到 WriteableBitmap 的同一区域中...快速复制 rect 像素或 smth。像那样。

那么,有没有一种方法可以快速地将 rect 从 RenderTargetBitmap 复制到 WriteableBitmap?

最佳答案

通过将整个 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));
}

关于wpf - 如何从 RenderTargetBitmap bitblit 到 WriteableBitmap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4901272/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com