gpt4 book ai didi

c# - 防止 Win2D Animated Canvas 清除

转载 作者:太空宇宙 更新时间:2023-11-03 23:24:04 27 4
gpt4 key购买 nike

我想保留 CanvasAnimatedControl 中最后绘制的帧以在其上绘制。
是否有内置功能可以执行此操作,还是我必须使用双缓冲。

我想实现 this使用 win2d。

最佳答案

如前所述here :

Controls are always cleared automatically by Win2D when a drawing session is created. CanvasRenderTargets are not. This way, apps have the ability to make incremental changes to CanvasRenderTargets, and avoid redrawing an entire scene every time.

CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget offscreen = new CanvasRenderTarget(device, width, height, 96);
using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
{
//ds.Clear(Colors.Black); // no clear and you are good to go.
ds.DrawRectangle(100, 200, 5, 6, Colors.Red);
}

Note that there is a method call to Clear. Without this, the bitmap will be initialized with undefined content.

To draw a CanvasRenderTarget to another drawing session, simply use DrawImage(ICanvasImage) or one of its overloads. For example:

void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
args.DrawingSession.DrawImage(offscreen, 23, 34);
}

关于c# - 防止 Win2D Animated Canvas 清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34381461/

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