-
[C#]PolygonC#/WPF_예제소스 2022. 2. 28. 17:39
XAML
<Polygon Points="0,0 300,100 300,200 0,300" > <Polygon.Fill> <ImageBrush ImageSource="C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg" Stretch="Uniform" AlignmentX="Left" /> </Polygon.Fill> </Polygon>
OR
C#
public MainWindow() { InitializeComponent(); CreateAPolygon(); } private void CreateAPolygon() { BitmapImage img1 = new BitmapImage(new Uri("E:/kis/WorkSpace/C#/PaintHD/PaintHD/Resources/sg2.jpg", UriKind.RelativeOrAbsolute)); // Create a blue and a black Brush SolidColorBrush yellowBrush = new SolidColorBrush(); yellowBrush.Color = Colors.Yellow; SolidColorBrush blackBrush = new SolidColorBrush(); blackBrush.Color = Colors.Black; ImageBrush songang = new ImageBrush(); songang.ImageSource = img1; // Create a Polygon Polygon imgPolygon = new Polygon(); imgPolygon.Stroke = blackBrush; //yellowPolygon.Fill = yellowBrush; imgPolygon.Fill = songang; imgPolygon.Stretch = Stretch.Uniform; imgPolygon.StrokeThickness = 2; #region[polyexp] // Create a collection of points for a polygon // 왼쪽 위(0.0) 에서 오른쪽아래로 (+,+) /*(0,0) -------------------------- | | | | | | (100,100) */ #endregion System.Windows.Point Point1 = new System.Windows.Point(0, 0); System.Windows.Point Point2 = new System.Windows.Point(300, 100); System.Windows.Point Point3 = new System.Windows.Point(300, 200); System.Windows.Point Point4 = new System.Windows.Point(0, 300); PointCollection polygonPoints = new PointCollection(); polygonPoints.Add(Point1); polygonPoints.Add(Point2); polygonPoints.Add(Point3); polygonPoints.Add(Point4); // Set Polygon.Points properties imgPolygon.Points = polygonPoints; // Add Polygon to the page LayoutRoot.Children.Add(imgPolygon); }
Polygon 회전
RotateTransform rotateTransform1 = new RotateTransform(180); //각도 rotateTransform1.CenterX = 250; //회전중심 X좌표 rotateTransform1.CenterY = 250; //회전중심 Y좌표 imgPolygon.RenderTransform = rotateTransform1; //polygon적용
728x90'C# > WPF_예제소스' 카테고리의 다른 글
[C#] 파일경로 설정 (0) 2022.03.29 [C#]Serial 버퍼 Data 이어 붙이기 (0) 2022.03.28 [C#]Viewport2DVisual3D (0) 2022.02.28 [C#] Thread vs Threadstart (0) 2022.02.18 [C#] datetime 차이값 구하기 (0) 2022.02.15 댓글