Search code examples
iosuiviewxamarin.iosskiaskiasharp

How to add rect using Skia Sharp and apply both fill color and stroke color to that object?


How to add rect or any shape using Skia Sharp and apply both fill color and stroke color to that object in iOS


Solution

  • To draw both fill and stroke, you will have to do two paint operations:

    // the rectangle
    var rect = SKRect.Create(10, 10, 100, 100);
    
    // the brush (fill with blue)
    var paint = new SKPaint {
        Style = SKPaintStyle.Fill,
        Color = SKColors.Blue
    };
    
    // draw fill
    canvas.DrawRect(rect, paint);
    
    // change the brush (stroke with red)
    paint.Style = SKPaintStyle.Stroke;
    paint.Color = SKColors.Red;
    
    // draw stroke
    canvas.DrawRect(rect, paint);