반응형
C# -- GraphicsPath.Flatten() 사용하기
https://www.c-sharpcorner.com/UploadFile/mahesh/understanding-and-using-graphics-paths-in-gdi/
GraphicsPath.Flatten (System.Drawing.Drawing2D.Matrix matrix, float flatness);
flatness
-- 곡선과 flattend 근사값 사이의 최대 허용 오차.
-- default = 0.25
-- 값이 작을수록, line segment 갯수가 증가함.
< 참고 >
Matrix.Translate (float offsetX, float offsetY)
-- 예 --
Matrix.Translate(100, 0) --> x 축으로 100 이동
Matrix.Translate(0, 100) --> y 축으로 100 이동
Matrix.Translate(100, 100) --> x, y 축으로각각 100 이동
--> Matrix 사용법
< 결과 >
< 소스 >
--
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Drawing.Drawing2D; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace graphicspath_test1 | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
} | |
private void Form1_Paint(object sender, PaintEventArgs e) | |
{ | |
var g = e.Graphics; | |
Point[] points = | |
{ | |
new Point(40,200), | |
new Point(80,300), | |
new Point(120,250), | |
new Point(80,200), | |
new Point(120,150), | |
new Point(80,100) | |
}; | |
using (GraphicsPath gPath = new GraphicsPath()) | |
using (Pen pen = new Pen(Color.Red, 3)) | |
{ | |
Matrix mx = new Matrix(); | |
mx.Translate(0, 20f); // y축으로 20 이동 | |
Matrix mx2 = new Matrix(); | |
mx2.Translate(20, 20f); // x축, y축으로 각각 20 이동 | |
gPath.AddCurve(points); // 곡선 | |
g.DrawPath(pen, gPath); | |
pen.Color = Color.Green; | |
gPath.Flatten(mx); // flatness default = 0.25 | |
g.DrawPath(pen, gPath); | |
gPath.Reset(); // 기존 data 삭제 | |
pen.Color = Color.Blue; | |
gPath.AddLines(points); // 직선 | |
g.DrawPath(pen, gPath); | |
for(int i= 0; i < points.Length; i++) | |
{ | |
points[i].Offset(150, 0); // x 축으로 150 이동 | |
} | |
gPath.Reset(); // 기존 data 삭제 | |
pen.Color = Color.Red; | |
gPath.AddCurve(points); | |
g.DrawPath(pen, gPath); | |
pen.Color = Color.Green; | |
gPath.Flatten(mx2, 5); // flatness = 5 | |
g.DrawPath(pen, gPath); | |
for (int i = 0; i < points.Length; i++) | |
{ | |
points[i].Offset(150, 0); // x 축으로 150 이동 | |
} | |
gPath.Reset(); // 기존 data 삭제 | |
gPath.AddCurve(points); | |
gPath.Flatten(mx, 10); // flatness = 10 | |
g.DrawPath(pen, gPath); | |
for (int i = 0; i < points.Length; i++) | |
{ | |
points[i].Offset(150, 0); // x 축으로 150 이동 | |
} | |
gPath.Reset(); // 기존 data 삭제 | |
gPath.AddCurve(points); | |
gPath.Flatten(mx, 20); // flatness = 20 | |
g.DrawPath(pen, gPath); | |
} | |
} | |
} | |
} |
반응형
'C#' 카테고리의 다른 글
C# -- property (속성) 사용법 (0) | 2019.03.16 |
---|---|
C# -- GraphicsPath HitTest & PathTypes (0) | 2019.03.05 |
C# -- 사칙연산 테스트 (0) | 2019.01.25 |
C# -- mouse 좌표 얻기 (화면 기준으로) (0) | 2019.01.24 |
C# -- method 순서대로 호출하는 Queue 만들기 (0) | 2018.12.28 |