Point control1 = new Point(100, 10);
Point control2 = new Point(150, 50);
Point end1 = new Point(200, 200);
Point control3 = new Point(100, 150);
Point control4 = new Point(50, 200);
Point end2 = new Point(10, 150);
Point[] bezierPoints ={start, control1, control2, end1, control3, control4, end2};
pen.EndCap = LineCapX.Round;
gx.DrawBeziers(pen, bezierPoints);
//Refresh
Invalidate();
XrossOne GDI 和本机 GDI 的矢量图形输出是相同的,但基数样条曲线除外。我的算法取自 Jean-Yves Queinec 撰写的文章 Smoothing Algorithm Using Bezier Curves。因此,您可能发现在它们的输出之间存在一些差异,如下面的图 2 所示。

图 2. DrawCurve/DrawClosedCurve 的输出
尽管大多数矢量图形呈现函数都已经得到实现,但仍然有一些工作需要完成。某些函数(DrawString、DrawImage、DrawPath 等等)直到下一个版本才可用。
渐变填充
在本机 GDI 中有五种画刷 — SolidBrush、LinearGradientBrush、PathGradientBrush、TextureBrush 和 HatchBrush。但是,在该版本中,只有 SolidBrush 和 LinearGradientBrush 可用。XrossOne GDI 支持 RadialGradientBrush 而不是 PathGradientBrush。下面的图 5 演示了渐变填充。

图 5. 渐变填充
代码示例 4
//Clear the background and reset the transform state
gx.Clear(Color.White);
gx.ResetTransform();
//Fill a rectangle with a black-white LinearGradientBrushX
Rectangle r = new Rectangle(20, 50, 300, 100);
Color c1 = Color.Black;
Color c2 = Color.White;
BrushX brush1 = new LinearGradientBrushX(r, c1, c2, 30F);
gx.FillRectangle(brush1, r);
//Fill a rectangle with a 7-color LinearGradientBrushX
r = new Rectangle(90, 100, 150, 100);
LinearGradientBrushX br = new LinearGradientBrushX(r,Color.Black,Color.Black, 60F);
ColorBlendX cb = new ColorBlendX();
cb.Positions=new float[7];
int i=0;
for(float f=0;f<=1;f =1.0f/6)
cb.Positions[i ]=f;
cb.Colors=new Color[]
{Color.Red,Color.Orange,Color.Yellow,Color.Green,Color.Blue,Color.Indigo,Color.Violet};
br.InterpolationColors=cb;
gx.TranslateTransform(160, 10);
gx.RotateTransform(60F);
gx.FillRectangle(br, r);
//Fill a rectangle with a 7-color RadialGradientBrushX
r.Y = 50;
RadialGradientBrushX brush2 = new RadialGradientBrushX(r, Color.Black,Color.Black, 220F);
brush2.InterpolationColors = cb;
gx.RotateTransform(-45F);
gx.TranslateTransform(-200, -170);
gx.FillRectangle(brush2, r);
//Refresh
Invalidate();
Alpha 通道合成
System.Drawing 命名空间中的 Color 结构在 .NET Framework 和 .NET Compact Framework 中都可用。区别在于 .NET Compact Framework 中禁用了 alpha 成分并且色调-饱和度-亮度 (HSB) 值不可用。幸运的是,alpha 通道合成可以完美地与 XrossOne GDI 协同工作(您可能已经从前面的图形示例中推断出这一点)。
性能
手持 PC 的 CPU 的功能确实通常要比标准 PC 的 CPU 差很多。繁重的计算可能使手持设备的响应速度降低,从而可能使用户变得不胜其烦。换句话说,性能对于手持设备软件而言至关重要。因此,在重大场合下使用 XrossOne Mobile GDI 之前,您可能希望分析它的总体性能。因为 GDI 中大多数对应于 .NET Compact Framework 的等效函数都不可用,所以基准测试是针对 .NET Framework 在 XrossOne Mobile GDI 和 GDI 之间进行的。测试是在下列类别中执行的:矢量图形呈现、二维变换和渐变填充。测试方案在相同的条件下执行。您可以在下载软件包中找到基准测试程序,并且可以在 http://www.xrossone.com/projects.php?menu=4 快速查看它们的图形输出。
XrossOne Mobile GDI 完全是用 C# 托管代码编写的,它的总体性能可以接受(参见下表),尽管二维变换和渐变填充需要在以后的版本中进一步优化。




