【问题标题】:SkiaSharp draw reversible shapesSkiaSharp 绘制可逆形状
【发布时间】:2022-12-03 19:21:25
【问题描述】:

有没有办法用 SkiaSharp 绘制可逆形状?

可逆我的意思是outColor = srcColor XOR dstColor,所以当你再次绘制相同的颜色时,原始颜色就会恢复。就像在 WinForms ControlPaint.DrawReversibleFrame 或(旧的)Windows FocusRects 中一样。

我正在使用 SkiaSharp 2.88.0

【问题讨论】:

    标签: skiasharp


    【解决方案1】:

    绘图时可以使用Exclusion混合模式,例如:

    // draw some random image on canvas
    var bitmap = SKBitmap.Decode(@"random.jpg");
    var info = new SKImageInfo(256, 256);
    using var surf = SKSurface.Create(info);
    var canvas = surf.Canvas;
    canvas.DrawBitmap(bitmap, info.Rect);
    
    // initialize paint with Exclusion blend mode
    var paint = new SKPaint {
        Color = SKColors.Yellow,
        Style = SKPaintStyle.Fill,
        BlendMode = SKBlendMode.Exclusion
    };
    
    // draw overlapping rectangles using the paint
    canvas.DrawRect(10, 10, 50, 50, paint);
    canvas.DrawRect(25, 25, 50, 50, paint);
    

    结果图片:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2011-12-23
      • 2018-09-24
      • 2021-09-19
      • 1970-01-01
      • 2018-11-28
      相关资源
      最近更新 更多