■ DrawingImage 클래스의 Drawing 속성을 사용해 드로잉 이미지를 만드는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); #region 색상 1을 생성한다. Color color1 = new Color(); color1.A = 255; color1.R = 204; color1.G = 204; color1.B = 255; #endregion #region 그라디언트 중단 1을 생성한다. GradientStop gradientStop1 = new GradientStop(); gradientStop1.Offset = 0.0; gradientStop1.Color = color1; #endregion #region 그라디언트 중단 2를 생성한다. GradientStop gradientStop2 = new GradientStop(); gradientStop2.Offset = 1.0; gradientStop2.Color = Colors.Purple; #endregion #region 선형 그라디언트 브러시를 생성한다. LinearGradientBrush linearGradientBrush = new LinearGradientBrush(); linearGradientBrush.GradientStops.Add(gradientStop1); linearGradientBrush.GradientStops.Add(gradientStop2); #endregion #region 펜을 생성한다. Pen pen = new Pen(); pen.Thickness = 10; pen.LineJoin = PenLineJoin.Round; pen.EndLineCap = PenLineCap.Round; pen.Brush = linearGradientBrush; #endregion #region 사각형 기하를 생성한다. RectangleGeometry rectangleGeometry = new RectangleGeometry(); rectangleGeometry.Rect = new Rect(0, 0, 50, 50); #endregion #region 타원 기하를 생성한다. EllipseGeometry ellipseGeometry = new EllipseGeometry(); ellipseGeometry.Center = new Point(75, 75); ellipseGeometry.RadiusX = 50; ellipseGeometry.RadiusY = 50; #endregion #region 선 기하를 생성한다. LineGeometry lineGeometry = new LineGeometry(); lineGeometry.StartPoint = new Point(75, 75); lineGeometry.EndPoint = new Point(75, 0 ); #endregion #region 기하 그룹을 생성한다. GeometryGroup geometryGroup = new GeometryGroup(); geometryGroup.Children.Add(rectangleGeometry); geometryGroup.Children.Add(ellipseGeometry ); geometryGroup.Children.Add(lineGeometry ); #endregion #region 기하 드로잉을 생성한다. GeometryDrawing geometryDrawing = new GeometryDrawing(); geometryDrawing.Pen = pen; geometryDrawing.Geometry = geometryGroup; #endregion #region 드로잉 그룹을 생성한다. DrawingGroup drawingGroup = new DrawingGroup(); drawingGroup.Children.Add(geometryDrawing); #endregion #region 드로잉 이미지를 생성한다. DrawingImage drawingImage = new DrawingImage(); drawingImage.Drawing = drawingGroup; #endregion #region 이미지를 생성한다. Image image = new Image(); image.Margin = new Thickness(10); image.Stretch = Stretch.None; image.Source = drawingImage; #endregion Content = image; } #endregion } } |