.net cf wince 贝兹 曲线图
分类: C#、Vs2005 MC1000 MC3000、MC3090 Wince 2011-12-14 23:41 642 人阅读 评论(3) 收藏 举
报
wince.netfloatexceptionnullstring
项目需要在 WINCE 设备中显示曲线图,由于 wince 采集器默认是不带画图的动态库
的,所以在网上找了一个动态库(XrossGDIPlus)来画图,关于 XrossGDIPlus 具体参考
http://www.microsoft.com/china/msdn/library/NetFramework/netcompactframework/dnnet
compXrossOne.mspx?mfr=true。 这个曲线是用路径显示的,画完曲线后,还要画显示的
坐标,原来的 XrossGDIPlus 库稍微做了调整,将 XrossGDIPlus 的缓冲图片暴露出来进行
绘制坐标,只有七个点以上才支持使用贝兹曲线进行显示,否则进行直线显示,为什么如此,
未找到 XrossGDIPlus 的原因,如果有明白的,请指点一下
设计期效果图如下,坐标轴的显示文字,字体颜色大小,坐标轴颜色都是可以设置的。
运行期的曲线效果图:显示在坐标区之外了,是因为临时调整截图显示的需要
调用方式: Point point1 = new Point(50, 1);
Point point2 = new Point(80, 10);
Point point3 = new Point(110, 20);
Point point4 = new Point(140, 30);
Point point5 = new Point(170, 5);
Point point6 = new Point(200, 50);
Point point7 = new Point(230, 40);
Point[] curvePoints ={
point1,
point2,
point3,
point4,
point5,
point6,
point7
};
int offset = 0;
int numSegments = 6;
float tension = 1f;
// Draw curve to screen.
curve.AddCurve(curvePoints, Color.Blue, 2, new
Font(FontFamily.GenericSansSerif, 6, FontStyle.Regular), "*");
curve.BeginCurve();
[csharp] view plaincopyprint?
1. 控件的源代码:
[csharp] view plaincopyprint?
1. using System;
2.
3. using System.Collections.Generic;
4. using System.ComponentModel;
5. using System.Drawing;
6. using System.Data;
7. using System.Text;
8. using System.Windows.Forms;
9. using XrossOne.Drawing;
10.
11. namespace FrontLinkControls
12. {
13. public struct CurveParameter
14. {
15. public Point[] pointList;
16. public Color curveColor;
17. public float curveWidth;
18. public Font curveFont;
19. public string curveAxisHead;
20. }
21.
22. public partial class FrontLinkCurve : UserControl
23. {
24. private GraphicsX gx;
25.
26. public FrontLinkCurve()
27. {
28. InitializeComponent();
29. gx = new GraphicsX(Width, Height);
30. }
31.
32. private float m_xBlankSize = 50; // 坐标轴左边空白的
距离
33. private float m_yBlankSize = 50; // 坐标轴右边空白的
距离
34.
35. #region 设置坐标轴属性
36.
37. private float m_YMax = 150; // X 轴的长度
38. private float m_XMax = 200; // Y 轴的长度
39. private float m_XCurveHeight = 5; // X 轴曲线的高度
40. private float m_YUnitSize = 30; // Y 轴的刻度单位
41. private float m_XUnitSize = 40; // X 轴的刻度单位
42. private Color m_CurveBackColor = Color.Orange; // 曲线背景的颜色
43. private Color m_CurveAxisColor = Color.Black; // 曲线线条
的颜色
44. private float m_CurveXWidth = 0.001f; // x 轴曲线的宽度
45. private float m_CurveYWidth = 0.001f; // y 轴曲线的宽度
46. private Color m_AxisColor = Color.Black; // X,Y 坐标轴的颜
色
47. private int m_AxisWidth = 2; // X,Y 坐标轴的宽
度
48. private int m_YAxisNameWidth = 5; // Y 轴名字的间隔
距离
49. private int m_XAxisNameWidth = 5; // X 轴名字的间隔
距离
50. private Font m_YFont = new Font(FontFamily.GenericSerif, 10, Font
Style.Regular); // Y 轴的名字字体
51. private Font m_XFont = new Font(FontFamily.GenericSerif, 10, Font
Style.Regular); // X 轴的名字字体
52.
53. // 用来绘制曲线图的关键点,依次将这些点连接起来即得到曲线图
54. private List<CurveParameter> m_curve = new List<CurveParameter>();
55.
56. public float XBlankSize
57. {
58. get
59. {
60. return this.m_xBlankSize;
61. }
62. set
63. {
64. if (value >= 0)
65. {
66. m_xBlankSize = value;
67. Invalidate();
68. }
69. }
70. }
71.
72. public float YBlankSize
73. {
74. get
75. {
76. return this.m_yBlankSize;
77. }
78. set
79. {
评论1