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?

More than 1 year has passed since last update.

MFCからSVG変換Advent Calendar 2022

Day 19

MFC から SVG クラスのパス呼び出しコードサンプル

Last updated at Posted at 2022-12-18

MFC と SvgImage のパス出力

MFC(GDI+) の場合以下のようになります。

    Gdiplus::Point poly[8];
    int nPoints = 8;
    poly[0] = Gdiplus::PointF(50,50);
    poly[1] = Gdiplus::PointF(100,100);
    poly[2] = Gdiplus::PointF(150,50);
    poly[3] = Gdiplus::PointF(200,100);
    poly[4] = Gdiplus::PointF(250,50);
    poly[5] = Gdiplus::PointF(300,100);
    poly[6] = Gdiplus::PointF(350,50);
    poly[7] = Gdiplus::PointF(400,100);
    Gdiplus::Pen pen(Color(255, 0, 0, 0));
    Gdiplus::GraphicsPath path;
    path.AddCurve(poly, nPoints, 0.5f);
	pGraphics->DrawPath(&pen, &path);

SvgImage への書き出しは Gdiplus::PathData クラスを利用するため、 Gdiplus::GraphicsPath を生成してそこから PathData を取得する形になります。
パスは GraphicsPath に書き出しを行うという手順を必要としますが、サンプルコードのカーディナルスプライン曲線だけでなく直線や円形なども同じ GraphicsPath オブジェクトに書き出しできるため、汎用性は高いといえます。

SvgImage に書き出すと以下のようになります。

    Gdiplus::Point poly[8];
    int nPoints = 8;
    poly[0] = Gdiplus::PointF(50,50);
    poly[1] = Gdiplus::PointF(100,100);
    poly[2] = Gdiplus::PointF(150,50);
    poly[3] = Gdiplus::PointF(200,100);
    poly[4] = Gdiplus::PointF(250,50);
    poly[5] = Gdiplus::PointF(300,100);
    poly[6] = Gdiplus::PointF(350,50);
    poly[7] = Gdiplus::PointF(400,100);
    Gdiplus::GraphicsPath path;
    path.AddCurve(poly, nPoints, 0.5f);
    Gdiplus::PathData pathData;
    path.GetPathData(&pathData);
    pImage->AddPathData(&pathData);
    pImage->AddAttrStroke(RGB(0, 0, 255), 1, PS_SOLID);
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?