Win2d 的使用 CanvasDrawingSession.Blend

Usage of Win2d CanvasDrawingSession.Blend

在我的项目中,我想在 Win2D 中做一种特殊的绘图。为此,我需要一个程序来用新几何体覆盖位图中的几何体,而不会丢失先前几何体的完整信息。 CanvasBlend.Min 函数似乎是要走的路。

我尝试了以下代码,但是 min 函数没有按预期工作。它不会将位图的几何形状与新几何形状进行比较。

using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
        {
            Rect myRect2 = new Rect();
            myRect2.X = 0;
            myRect2.Y = 0;
            myRect2.Width = 400;
            myRect2.Height = 500;

            ds.FillRectangle(myRect2, Windows.UI.Color.FromArgb(150, 255, 255, 255));

            ds.Blend = CanvasBlend.Min;

            Rect myRect1 = new Rect();
            myRect1.X = 0;
            myRect1.Y = 0;
            myRect1.Width = 500;
            myRect1.Height = 200;
            //this color should overwrite the color before, because it is the minimum
            ds.FillRectangle(myRect1, Windows.UI.Color.FromArgb(50, 255, 255, 255));
        }

参考document备注,需要将ClearColor属性设置为White并设置Opacity 属性 为 CanvasControl 中的“0.5”或“1”(如果你的 offscreen 来自 CanvasControl)查看 [= 的效果16=]。默认颜色为 Transparent in CanvasControl.

注意Windows.UI.Color.FromArgb(150, 255, 255, 255)Windows.UI.Color.FromArgb(50, 255, 255, 255)都是白色,需要将它们改为其他颜色如Windows.UI.Color.FromArgb(255, 255, 0, 0)Windows.UI.Color.FromArgb(255, 0, 0, 255)Windows.UI.Color.FromArgb()的第一个参数表示不透明度。