2010-08-17 5 views
2

alt text 다각형을 만들려면 아래 코드를 사용하십시오. 난 그냥 검은 점 으로이 다각형 표면을 채우기 위해, 내가 어떻게 할 수있는 다음,이 폴리곤을 비트 맵이나 메모리 스트림으로 변환하고 싶습니다. 어떻게해야합니까 ??도트로 채워지는 다각형 만들기

// Create a blue and a black Brush 
     SolidColorBrush yellowBrush = new SolidColorBrush(); 
     yellowBrush.Color = Colors.Transparent; 
     SolidColorBrush blackBrush = new SolidColorBrush(); 
     blackBrush.Color = Colors.Black; 

     // Create a Polygon 
     Polygon yellowPolygon = new Polygon(); 
     yellowPolygon.Stroke = blackBrush; 
     yellowPolygon.Fill = yellowBrush; 
     yellowPolygon.StrokeThickness = 4; 

     // Create a collection of points for a polygon 
     System.Windows.Point Point1 = new System.Windows.Point(50, 100); 
     System.Windows.Point Point2 = new System.Windows.Point(200, 100); 
     System.Windows.Point Point3 = new System.Windows.Point(200, 200); 
     System.Windows.Point Point4 = new System.Windows.Point(300, 30); 

     PointCollection polygonPoints = new PointCollection(); 
     polygonPoints.Add(Point1); 
     polygonPoints.Add(Point2); 
     polygonPoints.Add(Point3); 
     polygonPoints.Add(Point4); 

     // Set Polygon.Points properties 
     yellowPolygon.Points = polygonPoints;   

     // Add Polygon to the page 
     mygrid.Children.Add(yellowPolygon); 

답변

3

도트를 특정 순서로 배치해야합니까? 아니면 특정 순서없이 다각형에 점선 패턴을 지정하고 싶습니까?

특별한 주문이 필요하지 않은 경우 브러시, 예를 들어 DrawingBrush를 사용할 수 있습니다. http://msdn.microsoft.com/en-us/library/aa970904.aspx

이 브러시를 SolidColorBrush 대신 Polygon의 채우기 속성으로 설정할 수 있습니다.


이것은 MSDN의 링크에서 DrawingBrush의 예입니다,하지만 도트 표시하도록 수정 : 토르스텐 @

// Create a DrawingBrush and use it to 
// paint the rectangle. 
DrawingBrush myBrush = new DrawingBrush(); 

GeometryDrawing backgroundSquare = 
    new GeometryDrawing(
     Brushes.Yellow, 
     null, 
     new RectangleGeometry(new Rect(0, 0, 100, 100))); 

GeometryGroup aGeometryGroup = new GeometryGroup(); 
aGeometryGroup.Children.Add(new EllipseGeometry(new Rect(0, 0, 20, 20))); 

SolidColorBrush checkerBrush = new SolidColorBrush(Colors.Black); 

GeometryDrawing checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup); 

DrawingGroup checkersDrawingGroup = new DrawingGroup(); 
checkersDrawingGroup.Children.Add(backgroundSquare); 
checkersDrawingGroup.Children.Add(checkers); 

myBrush.Drawing = checkersDrawingGroup; 
myBrush.Viewport = new Rect(0, 0, 0.05, 0.05); 
myBrush.TileMode = TileMode.Tile; 

yellowPolygon.Fill = myBrush; 
+0

, 않기 위해, 단지 점선 패턴 모든 먹으 렴을하고 XAML 코드를 사용하고 있지 않다 여기, 그냥 그 이미지를 만들고 비트 맵으로 저장 하시겠습니까 ??? –

+0

@ deep : 코드 예제를 제공하기 위해 내 게시물을 편집했습니다. 그러나이 다각형을 비트 맵으로 저장하는 것에 관해서는 많은 조언을 드릴 수는 없습니다. 어쩌면이 링크가 도움이 될 수 있습니다. 비주얼 매개 변수로 Polygon을 전달합니다. http://www.wpftutorial.net/BitmapFromVisual.html – Torsten

+0

Torsten, 고마워요. –