프로그래밍/App 개발

[Xamarin] Draw dashed(dotted) arc with SkiaSharp (not using AddArc())

엽기토기 2021. 6. 14. 11:31
반응형

 

var dottedArcSize = Math.Min(info.Width, info.Height);

var dottdArcRect = new SKRect(
      StrokeWidth,
      StrokeWidth,
      dottedArcSize - StrokeWidth,
      dottedArcSize - StrokeWidth);

var dottedArcLinePaint = new SKPaint
{
    Color = Color.FromHex("#FF521F").ToSKColor(),
    StrokeWidth = 4.5f,
};

var dotYRatio = 0.22; 
var dotLength = 0.03;

var dotEmptyArcAngle = 60;

for (var degrees = 0; degrees < 360; degrees += 10)
{
    canvas.Save();
    canvas.RotateDegrees(degrees, dottdArcRect.MidX, dottdArcRect.MidY);
    if ((180 + dotEmptyArcAngle / 2 <= degrees && degrees < 360) || 
    	(0 <= degrees && degrees <= 180 - dotEmptyArcAngle / 2))
    {
        canvas.DrawLine(dottdArcRect.MidX, (float)(dottdArcRect.MidY * dotYRatio), dottdArcRect.MidX, (float)(dottdArcRect.MidY * (dotYRatio - dotLength)), dottedArcLinePaint);
    }
canvas.Restore();
}

dotYRatio  : 점선의 한 점 y 위치값 비율. 값이 낮을 수록 실선과 가까워지고, 높을 수록 실선과 멀어진다. 
dotLength : 점선의 한 점의 길이. 

StrokeWidth : 점선의 한 점의 너비.

 

10도에 한 개씩 점을 찍음.

반응형