正在阅读:用于.NET Compact Framework的强大二维图形引擎用于.NET Compact Framework的强大二维图形引擎

2005-06-09 10:17 出处: 作者:Xinjie ZHANG 责任编辑:moningfeng

线帽/联接装饰

  为了使 .NET Compact Framework 保持紧凑,GDI+ 桌面版本中的很多功能在该精简版本中不可用。其中一项功能是线帽/联接装饰。当然,当轮廓的宽度为一个像素时,任何装饰都似乎是不必要的,但是在 XrossOne GDI+ 中,线帽/联接装饰却是绘制不同大小的轮廓所必备的。XrossOne GDI+ 中支持四个线帽(Flat、Round、Triangle 和 Square)和三个线段联接(Bevel、Miter 和 Round)。上述装饰的示例如图 3 所示。


图 3. 线帽/联接装饰



  代码示例 2

//Clear the background and reset the transform state
gx.Clear(Color.White);
gx.ResetTransform();

//Draw a pentacle with Miter line join and Round line cap
PenX pen = new PenX(Color.Orange, 15);
Point p1 = new Point(150, 80);
Point p2 = new Point(100, 230);
Point p3 = new Point(240, 150);
Point p4 = new Point(60, 150);
Point p5 = new Point(200, 230);
Point[] points ={p1,p2,p3,p4,p5};
MatrixX m = new MatrixX();
m.Translate(-26, -70);
m.TransformPoints(points);
pen.LineJoin = LineJoinX.Miter;
pen.EndCap = LineCapX.Round;
pen.StartCap = LineCapX.Round;
gx.DrawLines(pen, points);

//Draw a pentacle with Bevel line join and Triangle line cap
pen = new PenX(Utils.FromArgb(0x80, Color.Blue), 15);
Point[] points2 ={p1,p2,p3,p4,p5};
m = new MatrixX();
m.Translate(-10, -30);
m.TransformPoints(points2);
pen.LineJoin = LineJoinX.Bevel;
pen.StartCap = LineCapX.Triangle;
gx.DrawLines(pen, points2);

//Draw a pentacle with Round line join and Round line cap
pen = new PenX(Utils.FromArgb(0x80, Color.BlueViolet), 20);
Point[] points3 ={p1,p2,p3,p4,p5};
m = new MatrixX();
m.Translate(-40, 20);
m.TransformPoints(points3);
pen.LineJoin = LineJoinX.Round;
pen.EndCap = LineCapX.Round;
gx.DrawLines(pen, points3);

//Refresh
Invalidate();



二维变换

  变换功能在 .NET Compact Framework 中不可用,这意味着,如果您要通过 30 度旋转来绘制椭圆,则您必须计算它的轮廓并且逐个像素地绘制它。在大多数情况下,这是乏味和低效的。幸运的是,XrossOne GDI+ 提供了功能完善的二维变换。您可以移动、缩放和旋转您喜欢的任何图形,如图 4 所示。


图 4. 二维变换



  代码示例 3

//Clear the background and reset the transform state
gx.Clear(Color.White);
gx.ResetTransform();

//Draw a rectangle and apply scale transform to it
Color c = Utils.FromArgb(0x80, Color.Orange);
PenX pen = new PenX(c, 7.5f);
pen.LineJoin = LineJoinX.Miter;
gx.DrawRectangle(pen, 10, 10, 50, 50);
gx.ScaleTransform(3, 3);
gx.DrawRectangle(pen, 10, 10, 50, 50);

//Draw a series of ellipses and rotate 10 degrees between the preceding and the successor
c = Utils.FromArgb(0x80, Color.BlueViolet);
pen = new PenX(c, 5.5f);
gx.ScaleTransform(0.25F, 0.25F);
gx.RotateTransform(-40);
for (int j = 0; j < 10; j ++)
{
gx.RotateTransform(10);
gx.DrawEllipse(pen, 100, 50, 50, 130);
}

//Draw a series of triangles and apply translate transform to them
pen = new PenX(Utils.FromArgb(0x80, Color.Blue), 10);
Point p1 = new Point(120, 80);
Point p2 = new Point(100, 200);
Point p3 = new Point(140, 200);
Point[] points ={p1,p2,p3};
gx.Transform = new MatrixX();
pen.LineJoin = LineJoinX.Round;
for (int i = 0; i <= 40; i +=10)
{
gx.TranslateTransform(20, 10);
gx.DrawPolygon(pen, points);
}

//Refresh
Invalidate();


键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品