Fill polygon with image/bitmap

Is there a option to fill a drawn polygon with an image/bitmap like image brushes on WPF?

Tagged:

Answers

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    Ok, I found this myself. You have to use SKShader for this and assign this shader to SKPaint.Shader.

    Now I want to do the same with PathEffects. But I get strange outputs:

    I use the following code:

    paint.Style = SKPaintStyle.Stroke;
    paint.Color = fillColor.ToSkia(opacity);
    float scale = 10.0f;
    SKPath fillPath = new SKPath();
    SKMatrix matrix;
    fillPath.MoveTo(10, 10);
    fillPath.LineTo(0, 0);
    fillPath.MoveTo(0, 10);
    fillPath.LineTo(10, 0);
    matrix = SKMatrix.MakeScale(scale, scale);
    paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
    canvas.ClipPath(path);
    canvas.DrawPath(path, paint);
    

    If I don't clip the path, I get the following result:

    Thank you for your help.

Sign In or Register to comment.