0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Skiaの実践:折れ線や曲線

Last updated at Posted at 2025-11-08

ここでは、SkiaSharpを使って折れ線や曲線を描画する方法について詳しく説明します。

折れ線の基本形

折れ線を描画するには、SKPathクラスでパスを作成し、DrawPathメソッドで描画します。

DrawPointsメソッドを使う方法を紹介している記事もありますが、DrawPathを使う方が柔軟で扱すく、綺麗な折れ線が描画できるので、こちらを推奨します。

using var paint = new SKPaint {
    Color = SKColors.Black,
    IsAntialias = true,
    Style = SKPaintStyle.Stroke,
    StrokeWidth = 20,
};
// 折れ線のパスを作成
using var path = new SKPath();
path.MoveTo( 50, 150 );
path.LineTo( 100, 50 );
path.LineTo( 150, 150 );
path.LineTo( 200, 50 );
path.LineTo( 250, 150 );
// パスを描画
canvas.DrawPath( path, paint );

実行すると、以下のように、折れ線が描画されます。

polyline.png

角を落とす

折れ線の角を落とすには、SKPaintStrokeJoinプロパティを設定します。

効果
SKStrokeJoin.Miter 角が尖る(デフォルト)
SKStrokeJoin.Bevel 角が斜めにカットされる
SKStrokeJoin.Round 角が丸くなる

ここでは、SKStrokeJoin.Roundを設定してみましょう。

paint.StrokeJoin = SKStrokeJoin.Round;

実行すると、以下のように、角が丸くなった折れ線が描画されます。

polyline_rounded.png

角をもっと丸くする

角をもっと丸くするには、PathEffectプロパティにSKPathEffect.CreateCornerを設定します。ただし、これは幾何学的、数学的に厳密な丸みを与えるものではなく、あくまで視覚的に丸く見せるための効果なので注意してください。

paint.PathEffect = SKPathEffect.CreateCorner( 30 );

実行すると、以下のように、さらに丸みを帯びた折れ線が描画されます。

polyline_more_rounded.png

曲線の描画

曲線を描画するには、3次ベジェ曲線を使う方法と、円錐曲線を使う方法があります。

3次ベジェ曲線

SKPathCubicToメソッドで、3次ベジェ曲線の二つの制御点と終点を指定して描画します。

using var path = new SKPath();
path.MoveTo( 50, 100 );
path.CubicTo( 
    100, -50, // 第一制御点
    200, 250, // 第二制御点
    250, 100  // 終点
);
canvas.DrawPath( path, paint );

実行すると、以下のように、曲線が描画されます。

bezier_curve.png

円錐曲線

SKPathConicToメソッドで、一つの制御点と終点、そしてウェイトを指定して描画します。ウェイトは曲線の形状に影響を与える係数で、1.0に近いほど制御点に引き寄せられ、0.0に近いほど直線に近づきます。

using var path = new SKPath();
path.MoveTo( 50, 150 );
path.ConicTo( 
    200, -50, // 制御点
    250, 150, // 終点
    0.5f      // ウェイト
);
canvas.DrawPath( path, paint );

実行すると、以下のように、円錐曲線が描画されます。

conic_curve.png


総合目次

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?