C#を使い画像ファイルに線を描く
Mon.15.10.2007 Posted in コンピュータ
 C#を使い、用意した画像ファイルに線を追加する方法。

 resultPictureはBitmap型。ResultPictureBoxはPictureBox型。


//Graphicsオブジェクトの作成
Graphics g = Graphics.FromImage(resultPicture);
//ベジエ曲線の形状を決定する4つの点
Point point1 = new Point(30, 20);
Point point2 = new Point(120, 40);
Point point3 = new Point(60, 120);
Point point4 = new Point(150, 100);

//Penオブジェクトの作成(幅1の黒色)
Pen blackPen = new Pen(Color.Black, 1);
//ベジエ曲線に接する二本の直線を引く
g.DrawLine(blackPen, point1, point2);
g.DrawLine(blackPen, point3, point4);

//Penオブジェクトの作成(幅1の青色)
Pen bluePen = new Pen(Color.Blue, 1);
//ベジエスプラインを描画
g.DrawBezier(bluePen, point1, point2, point3, point4);

//リソースを開放する
bluePen.Dispose();
blackPen.Dispose();
g.Dispose();

ResultPictureBox.Image = resultPicture;



参考
曲線を描く: .NET Tips: C#, VB.NET, Visual Studio
関連エントリー


« CLAUSTHALER CLASSICというノンアルコールビールを飲んだ | Home | バックアップの取り方 »

comments

コメントの投稿


管理者にだけ表示を許可する

trackback


この記事にトラックバックする(FC2ブログユーザー)

topBack to TOP