SkiaSharp
SkiaSharp copied to clipboard
[QUESTION] Filling a polygon with hatch style
I'm trying to fill a polygon with fill hatch style and border, but it looks like drawn paths doesn't fit. What am I doing wrong? 😓
Thanks!
Code:
SKBitmap skBitmap = new SKBitmap(pictureBox.Width, pictureBox.Height);
float xCenter = pictureBox.Width / 2;
float yCenter = pictureBox.Height / 2;
float side = 250.0f;
var path = new SKPath();
path.MoveTo(0, side / 2);
path.LineTo(side / 2, 0);
path.LineTo(side, side / 2);
path.LineTo(side / 2, side);
path.Close();
float scale = 16.0f;
var scaleMatrix = SKMatrix.MakeScale(scale, scale);
var fillPaint = new SKPaint
{
Color = SKColors.Blue,
StrokeWidth = 0.5f,
PathEffect = SKPathEffect.Create2DLine(2.0f, scaleMatrix)
};
var paint = new SKPaint
{
Color = SKColors.Red,
Style = SKPaintStyle.Stroke,
StrokeWidth = 2.0f
};
using (var canvas = new SKCanvas(skBitmap))
{
canvas.Translate(xCenter - (side / 2), yCenter - (side / 2));
canvas.DrawPath(path, fillPaint);
canvas.DrawPath(path, paint);
}
fillPaint.Dispose();
paint.Dispose();
pictureBox.Image = skBitmap.ToBitmap();
Result

I could fix it using:
var scaleMatrix = SKMatrix.MakeScale(1.0f, scale);