简体   繁体   English

如何着色装载SkiaSharp的黑白SVG?

[英]How to colorize black and white SVG loaded with SkiaSharp?

I'm playing with new release of SkiaSharp (1.55) that support loading SVG on Xamarin.Android (and not only). 我正在玩新版本的SkiaSharp(1.55),它支持在Xamarin.Android(而不仅仅是)上加载SVG。 Due to the fact that it was release less than 10 days ago I couldn't find so much documentation. 由于它是在不到10天前发布的事实,我找不到这么多文档。

After loading an SVG in black and white, I'd like to colorize it (changing the foreground filling color from black to any color I need). 加载黑白SVG后,我想将它着色(将前景填充颜色从黑色改为我需要的任何颜色)。 This is what I'm doing. 这就是我正在做的事情。

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

The above code works fine, but I have the impression that I'm not using the right filter. 上面的代码工作正常,但我的印象是我没有使用正确的过滤器。

  1. Is there any filter with a kind of "colorize" function? 是否有任何具有“着色”功能的过滤器?
  2. How to achieve the same for background pixels instead? 如何实现相同的背景像素呢?
  3. Any easy way to invert the colors? 任何简单的方法来反转颜色?

Detailed explanations are welcome. 欢迎详细解释。

I think the color filter is the correct filter (since you are changing colors), but you can also try using the blend modes instead of lighting: 我认为滤色镜是正确的滤镜(因为你正在改变颜色),但你也可以尝试使用混合模式而不是光照:

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);
}

As a result of the blend modes, you can do a whole lot of this, even inverting colors. 作为混合模式的结果,您可以做很多这样的事情,甚至可以反转颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM