【问题标题】:How to colorize black and white SVG loaded with SkiaSharp?如何为使用 SkiaSharp 加载的黑白 SVG 着色?
【发布时间】:2016-11-19 15:21:36
【问题描述】:

我正在使用新版本的 SkiaSharp (1.55),它支持在 Xamarin.Android 上加载 SVG(不仅如此)。由于它是在不到 10 天前发布的,我找不到这么多文档。

加载黑白 SVG 后,我想对其进行着色(将前景填充颜色从黑色更改为我需要的任何颜色)。这就是我正在做的。

using (var paint = new SKPaint())
{
    paint.ColorFilter = SKColorFilter.CreateLighting(SKColors.White, SKColor.Parse("#FF0000"));
}

上面的代码运行良好,但我觉得我没有使用正确的过滤器。

  1. 有没有带有“着色”功能的滤镜?
  2. 如何为背景像素实现相同的效果?
  3. 有任何简单的反转颜色的方法吗?

欢迎详细解释。

【问题讨论】:

    标签: android svg xamarin xamarin.android skiasharp


    【解决方案1】:

    我认为颜色过滤器是正确的过滤器(因为您正在更改颜色),但您也可以尝试使用混合模式而不是照明:

    using (var paint = new SKPaint()) {
        paint.ColorFilter = SKColorFilter.CreateBlendMode(
            SKColors.Red,       // the color, also `(SKColor)0xFFFF0000` is valid
            SKBlendMode.SrcIn); // use the source color
    
        canvas.DrawPicture(svgPicture, paint);
    }
    

    由于混合模式,您可以做很多这样的事情,甚至反转颜色。

    【讨论】:

      猜你喜欢
      • 2015-09-18
      • 2014-01-07
      • 2022-06-16
      • 2013-07-26
      • 2017-04-03
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      相关资源
      最近更新 更多