silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 引路蜂二维图形库示例:绘制各种几何图形大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

这个例子说明如何使用Graphics2D对象来绘制各种几何图形。引路蜂二维图形库中定义里多种基本几何图形,如,点,线段,曲线和矩形等。接口PathIterator定义了从Path中获取路径元素的方法。接口IShape定义了描述几何图形公用的方法。 点 类Point定义了二维空间位置在(x,y)一个点。Point point = new Point (x, y); 创建一个点对象。此外Point类也

这个例子说明如何使用Graphics2D对象来绘制各种几何图形。引路蜂二维图形库中定义里多种基本几何图形,如,点,线段,曲线和矩形等。接口PathIterator定义了从Path中获取路径元素的方法。接口IShape定义了描述几何图形公用的方法。@H_874_19@

@H_874_19@

类Point定义了二维空间位置在(x,y)一个点。Point point = new Point (x,y); 创建一个点对象。此外Point类也提供了计算两点之间距离的方法等。@H_874_19@

线段@H_874_19@

类Line定义了平面上一条线段。下面代码绘制一条线段。@H_874_19@

// draw Line2D.Double
graphics2D.draw (pen,new Line(x1,y1,x2,y2));@H_874_19@

Silverlight 引路蜂二维图形库示例:绘制各种几何图形

@H_874_19@

图形库中类Pen可以用来定义绘制线段的线型,线宽等参数。@H_874_19@

二次曲线@H_874_19@

类QuadCurve实现了IShape接口,它定义了平面上一条二次曲线。二次曲线可以通过曲线的两个端点和一个控制点来定义。@H_874_19@

// create new QuadCurve
QuadCurve q = new QuadCurve();
// draw QuadCurve2D with set coordinates
graphics2D.draw(pen,q.setCurve(x1,ctrlx,ctrly,y2));@H_874_19@

Silverlight 引路蜂二维图形库示例:绘制各种几何图形

@H_874_19@

三次曲线@H_874_19@

类CubicCurve同样实现了IShape接口,它定义了平面上一条三次曲线。和二次曲线类似,三次曲线可以通过曲线的两个端点和两个控制点来定义。@H_874_19@

// create new CubicCurve
CubicCurve c = new CubicCurve();
// draw CubicCurve with set coordinates
graphics2D.draw(pen,c.setCurve(x1,ctrlx1,ctrly1,ctrlx2,ctrly2,y2));@H_874_19@

Silverlight 引路蜂二维图形库示例:绘制各种几何图形

@H_874_19@

矩形@H_874_19@

类Rectangle是RectangleShape的子类。RectangleShape同样实现了IShape接口。 Rectangle可以通过一个点(x,y)和大小(Dimsension)来定义。@H_874_19@

// draw Rectangle
graphics2D.draw(pen,new Rectangle(x,y,rectwidth,rectheight));@H_874_19@

类RoundRectangle定义了带圆角的矩形。圆角矩形可以由下列参数来定义:位置,宽度,长度,圆角宽度,圆角长度。@H_874_19@

// draw RoundRectangle
graphics2D.draw(pen,new RoundRectangle(x,rectheight,10,10));@H_874_19@

Silverlight 引路蜂二维图形库示例:绘制各种几何图形

@H_874_19@

椭圆@H_874_19@

类Ellipse通过椭圆的外接矩形来定义其大小。@H_874_19@

// draw Ellipse
graphics2D.draw(pen,new Ellipse(x,rectheight));@H_874_19@

Silverlight 引路蜂二维图形库示例:绘制各种几何图形

@H_874_19@

圆弧@H_874_19@

类Arc通过外接矩形,起始角度,角度,封闭类型来定义。@H_874_19@

// draw Arc
graphics2D.draw(pen,new Arc(x,90,135,Arc.oPEN));@H_874_19@

Silverlight 引路蜂二维图形库示例:绘制各种几何图形

@H_874_19@

下面代码显示了多种几何图形。@H_874_19@

private void SharpsDemo2D()
{
 Color bg = Color.White;
 Color fg = Color.black;
 Color red = Color.Red;
 Color white = Color.White;
 Pen pen = new Pen(fg,1);
 SolidBrush brush = new SolidBrush(red);
 //Clear the canvas with white color.
 graphics2D.Clear(bg);
 Dimension d = new Dimension(screenWidth,screenHeight);
 int gridWidth = d.Width / 2;
 int gridHeight = d.Height / 6;
 
 int x = 5;
 int y = 7;
 int rectWidth = gridWidth - 2 * x;
 int StringY = gridHeight - 3 - 2 - 16;
 int rectHeight = StringY - y - 2;
 graphics2D.Draw(pen,new Line(x,y + rectHeight - 1,x + rectWidth,y));
 x += gridWidth;
 graphics2D.Draw(pen,rectWidth,rectHeight));
 x += gridWidth;
 x = 5;
 y += gridHeight;
 StringY += gridHeight;
 graphics2D.Draw(pen,rectHeight,10));
 x += gridWidth;
 graphics2D.Draw(pen,Arc.open));
 x = 5;
 y += gridHeight;
 StringY += gridHeight;
 graphics2D.Draw(pen,rectHeight));
 x += gridWidth;
 // draw GeneralPath (polygon)
 int[] x1Points = { x,x,x + rectWidth };
 int[] y1Points = { y,y + rectHeight,y };
 Path polygon = new Path(Path.WindEvenOdd,x1Points.Length);
 polygon.MoveTo(x1Points[0],y1Points[0]);
 for (int index = 1; index < x1Points.Length; index++)
 {
  polygon.LineTo(x1Points[index],y1Points[index]);
 }
 polygon.ClosePath();
 graphics2D.Draw(pen,polygon);
 x = 5;
 y += gridHeight;
 StringY += gridHeight;
 int[] x2Points = { x,x + rectWidth };
 int[] y2Points = { y,y };
 Path polyline = new Path(Path.WindEvenOdd,x2Points.Length);
 polyline.MoveTo(x2Points[0],y2Points[0]);
 for (int index = 1; index < x2Points.Length; index++)
 {
  polyline.LineTo(x2Points[index],y2Points[index]);
 }
 graphics2D.Draw(pen,polylinE);
 x += gridWidth;
 graphics2D.SetPenAndBrush(pen,brush);
 graphics2D.Fill(null,rectHeight));
 graphics2D.Draw(null,rectHeight));
 x = 5;
 y += gridHeight;
 StringY += gridHeight;
 Color[] colors = new Color[] { red,white };
 int[] fractions = new int[] { 0,255 };
 LinearGradientBrush redtowhite =
   new LinearGradientBrush(x,fractions,colors,Brush.NoCyclE);
 graphics2D.SetPenAndBrush(pen,redtowhitE);
 graphics2D.Fill(null,10));
 graphics2D.Draw(null,10));
 x += gridWidth;
 graphics2D.SetPenAndBrush(pen,Arc.Chord));
 graphics2D.Draw(null,Arc.Chord));
 x = 5;
 y += gridHeight;
 StringY += gridHeight;
 int[] x3Points = { x,x + rectWidth };
 int[] y3Points = { y,y };
 Path filledPolygon = new Path(Path.WindEvenOdd,x3Points.Length);
 filledPolygon.MoveTo(x3Points[0],y3Points[0]);
 for (int index = 1; index < x3Points.Length; index++)
 {
  filledPolygon.LineTo(x3Points[index],y3Points[index]);
 }
 filledPolygon.ClosePath();
 graphics2D.SetPenAndBrush(pen,filledPolygon);
 graphics2D.Draw(null,filledPolygon);
 
}


Silverlight 引路蜂二维图形库示例:绘制各种几何图形@H_874_19@@H_874_19@@H_874_19@

大佬总结

以上是大佬教程为你收集整理的Silverlight 引路蜂二维图形库示例:绘制各种几何图形全部内容,希望文章能够帮你解决Silverlight 引路蜂二维图形库示例:绘制各种几何图形所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。