是否可以同时绘制带有轮廓和填充的对象?
Is it possible to draw object with outline and fill at the same time?
例如,我想绘制一个多边形,或者以轮廓颜色与填充(“内容”)颜色不同的方式绘制文本。我在 SKPaint
中发现了 属性 ColorF
,我猜只需要将样式更改为 StrokeAndFill
—— 好吧,我猜错了,我得到的是单一颜色。在下面的示例中,单一颜色是 ColorF
(DrawText
是 Color
)。
视觉上我可以使用两遍来达到预期的效果,但我想知道这是否可以一步完成。
绘制和填充多边形示例:
using (var sk_paint = new SKPaint
{
Style = SKPaintStyle.StrokeAndFill,
Color = outline_color,
ColorF = fill_color,
IsAntialias = true,
StrokeWidth = (float)thickness
})
{
using (var path = new SKPath { FillType = SKPathFillType.EvenOdd })
{
path.MoveTo(points.First().x, points.First().y);
foreach (var p in points.Skip(1))
path.LineTo(p.x, p.y);
path.Close();
canvas.DrawPath(path, sk_paint);
}
}
至于我找到的台词 (RTFM ;-)) https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/curves/effects#path-outlining 我想知道 ColorF
是不是某种剩余的东西。反正我还是对画带轮廓的文字感兴趣
答案是:不能。 SKPaint
的两个颜色属性(Color
和 ColorF
)在内部设置相同的 SKColorF
值(Color
被转换为 ColorF
)。 ColorF
中的 'F' 表示 RGBA 值存储为浮点数而不是字节。
例如,我想绘制一个多边形,或者以轮廓颜色与填充(“内容”)颜色不同的方式绘制文本。我在 SKPaint
中发现了 属性 ColorF
,我猜只需要将样式更改为 StrokeAndFill
—— 好吧,我猜错了,我得到的是单一颜色。在下面的示例中,单一颜色是 ColorF
(DrawText
是 Color
)。
视觉上我可以使用两遍来达到预期的效果,但我想知道这是否可以一步完成。
绘制和填充多边形示例:
using (var sk_paint = new SKPaint
{
Style = SKPaintStyle.StrokeAndFill,
Color = outline_color,
ColorF = fill_color,
IsAntialias = true,
StrokeWidth = (float)thickness
})
{
using (var path = new SKPath { FillType = SKPathFillType.EvenOdd })
{
path.MoveTo(points.First().x, points.First().y);
foreach (var p in points.Skip(1))
path.LineTo(p.x, p.y);
path.Close();
canvas.DrawPath(path, sk_paint);
}
}
至于我找到的台词 (RTFM ;-)) https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/curves/effects#path-outlining 我想知道 ColorF
是不是某种剩余的东西。反正我还是对画带轮廓的文字感兴趣
答案是:不能。 SKPaint
的两个颜色属性(Color
和 ColorF
)在内部设置相同的 SKColorF
值(Color
被转换为 ColorF
)。 ColorF
中的 'F' 表示 RGBA 值存储为浮点数而不是字节。