먼저 링크에서 DrawingVisual
Class
를 찾고 있습니다 :
는
DrawingVisual과 도형, 이미지 또는 텍스트를 렌더링하는 데 사용되는 경량 그리기 클래스입니다. 이 클래스는 레이아웃 또는 이벤트 처리 기능을 제공하지 않으므로 가벼운 것으로 간주되므로 성능이 향상됩니다. 이러한 이유로 드로잉은 배경과 클립 아트에 이상적입니다.
당신은 또한 당신이 포인트 컬렉션을 추가 할 수 있습니다 PolyLine Class에 액세스 할 수 있습니다. 이 예는 MSDN Forum example
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
float x0 = 100f;
float y0 = 100f;
Polyline myPoly = new Polyline();
PointCollection polyPoints = myPoly.Points;
Point[] points = new Point[200];
for (int j = 0; j < 200; j++)
{
points[j] = new Point();
points[j].X = x0 + j;
points[j].Y = y0 -
(float)(Math.Sin((2 * Math.PI * j)/200) * (200/(2 * Math.PI)));
}
for (int i = 0; i < points.Length ; i++)
{
polyPoints.Add(points[i]);
}
myPoly.Stroke = Brushes.Green;
myPoly.StrokeThickness = 5;
StackPanel mainPanel = new StackPanel();
mainPanel.Children.Add(myPoly);
this.Content = mainPanel;
}
}
수정과 수정 된 MSDN의 예입니다
이
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
float x0 = 100f;
float y0 = 100f;
Point[] points = new Point[200];
for (int j = 0; j < 200; j++)
{
points[j] = new Point();
points[j].X = x0 + j;
points[j].Y = y0 -
(float)(Math.Sin((2 * Math.PI * j)/200) * (200/(2 * Math.PI)));
}
DrawingBrush db = new DrawingBrush(CreateDrawingVisualRectangle(points).Drawing);
StackPanel mainPanel = new StackPanel();
mainPanel.Background = db;
this.Content = mainPanel;
}
private DrawingVisual CreateDrawingVisualRectangle(Point[] pointarray)
{
DrawingVisual drawingVisual = new DrawingVisual();
// Retrieve the DrawingContext in order to create new drawing content.
DrawingContext drawingContext = drawingVisual.RenderOpen();
// Create a rectangle and draw it in the DrawingContext.
for (int i = 0; i < pointarray.Length-1; i++)
{
drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Blue), 2), pointarray[i], pointarray[i + 1]);
}
// Persist the drawing content.
drawingContext.Close();
return drawingVisual;
}
}
내가이 클래스의 도움으로 파형 (예를 들어, 사인파)를 그릴 수 있습니까? – abhi154
@ abhi154 예, ['DrawingContext'] (http://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext (v = vs.110) .aspx) 클래스를 사용하십시오. 그것은 WinForms 그래픽 객체와 같은 유형의 메소드를가집니다. –