[英]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. 上面的代码工作正常,但我的印象是我没有使用正确的过滤器。
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.