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?

【C#】DrawLine(系)で太い線を描画するときとGraphicsPath使用時のちょっとした注意点

Last updated at Posted at 2025-03-13

DrawLine(系)で太い線を描画するときのちょっとした注意点

※DrawLine系: DrawLine, DrawLines, DrawPath, ... など(実質Draw系)

津波情報の描画にGeoJSONのLineString,MultiLineString形式の地図データを使っていますが、なぜか欠けることがある問題が起きました。

↓小笠原諸島
image.png

↓上のものは後述(GraphicsPath使用時の注意点)

(よく見ると佐渡などで欠けている)

始点と終点は一致していますし、PenにLineJoin.Round、GraphicsにSmoothingMode.AntiAliasを設定しても変わりません。

解決方法

PointではなくPointF, intではなくfloat を使えば(たぶん)OK(サイズが小さいと欠けます)

(やり方と命名が変なのは置いといて)例がないのは寂しいので置いときます。.NET9, System.Text.Jsonです。

var pointsList = new List<List<PointF>>();
if ((string)json_1_geo["type"]! == "LineString")
{
    var points = new List<PointF>();
    foreach (var json_2 in json_1_geo["coordinates"]!.AsArray())
        points.Add(new PointF(((float)json_2![0]! - 120f) * 20f, (50f - (float)json_2[1]!) * 20f));
    pointsList.Add(points);
}
else
    foreach (var json_2 in json_1_geo["coordinates"]!.AsArray())
    {
        var points = new List<PointF>();
        foreach (var json_3 in json_2!.AsArray())
            points.Add(new PointF(((float)json_3![0]! - 120f) * 20f, (50f - (float)json_3[1]!) * 20f));
        pointsList.Add(points);
    }

GraphicsPath使用時のちょっとした注意点

Multh**形式のGeoJSONをGraphicsPathを使用して適当にやっていると、異なる地物がつながります(上の方のポストでも一部起きている)。

解決方法

GraphicsPath.Add**()の前か後にGraphicsPath.StartFigure(); をするだけでOK。

おまけ

津波情報を表示している自作ソフト

https://github.com/Ichihai1415/QuakeMapFast 編集時点未作成

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?