본문 바로가기
삽질기초/SW

C# 기본 그래픽

by @가을바람 2009. 11. 4.
// c# 그래픽 - 경로그리기, 선그리기, picturebox에서 이미지 축 회전
//Graphics graphics = this.CreateGraphics();
//Graphics graphics = pictureBox1.CreateGraphics();
//Pen pen = new Pen(Color.Blue);

//pen.Dispose();
//graphics .Dispose();




private void drawpath() //경로 그리기
{
Point[] point = new Point[3];
point[0].X = 10;
point[0].Y = 10;
point[1].X = 200;
point[1].Y = 10;
point[2].X = 300;
point[2].Y = 300;
Graphics g = pictureBox1.CreateGraphics();
Pen p = new Pen(Color.Blue);
GraphicsPath path = new GraphicsPath();

path.AddLines(point);
g.DrawPath(p, path);



path.Dispose();
p.Dispose();
g.Dispose();

}



private void DrawAxis() //그냥 그려보기.
{
Point p1 = new Point();
Point p2 = new Point();
Pen pen = new Pen(Color.Blue);
Graphics g = pictureBox1.CreateGraphics();

p1.X = 200; p1.Y = 0;
p2.X = 200; p2.Y = 400;
g.DrawLine(pen, p1, p2);       // Graphics의 선을 그리는 함수
p1.X = 0; p1.Y = 200;
p2.X = 400; p2.Y = 200;
g.DrawLine(pen, p1, p2);
p1.X = 0; p1.Y = 202;
p2.X = 0; p2.Y = 198;
for (int i = 0; i <= 40; i++)
{
p1.X += 10;
p2.X += 10;
g.DrawLine(pen, p1, p2);
}
p1.X = 202; p1.Y = 0;
p2.X = 198; p2.Y = 0;
for (int i = 0; i <= 40; i++)
{
p1.Y += 10;
p2.Y += 10;
g.DrawLine(pen, p1, p2);
}


pen.Dispose();
g.Dispose();
}



private void RotateAxis() //pictureBox의 중앙을 탐색, 축을 회전.
{
Graphics g = pictureBox1.CreateGraphics();
Pen p = new Pen(Color.Blue,1);

g.TranslateTransform(200, 200);
g.RotateTransform(-90);
g.DrawLine(p, 0, 0, 200, 0);
g.DrawLine(p, 10, 10, 10, -10);



p.Dispose();
g.Dispose();
}

'삽질기초 > SW' 카테고리의 다른 글

c언어 기초 행렬 연산  (0) 2010.01.31
c# 전역 비트맵. 다시그리기.  (0) 2009.11.04
CString LPSTR WCHAR*  (0) 2009.08.30
.NET Framework의 개요  (0) 2009.08.30
serial commution  (0) 2009.08.29