【STM32 .Net MF开发板学习-03】TinyGUI绘图示例

系统 1604 0

.Net Micro Framework 官方图形库是 WPF ,由于目前 ST Cortex-M3 开发板 RAM 太小,最大才 512K (常见是 128K 256k ),并且 Cortex-M3 CPU 主频也不太高,运行 WPF 图形框架显得过于重了,所以我这边推出了轻量级图形库 TinyGUI (此外,我也推出了一个 WinForm 的框架,和 .Net Framework 保持兼容,适合喜欢 WinForm 开发的用户,不过这个不是轻量级的,参见《 开源 System.Windows.Forms 库,让 .Net Micro Framework 界面开发和上位机一样简单 》)。

TinyGUI 的相关介绍,在我早期的一篇 Blog 中已经有介绍了,所以不知道 TinyGUI 为何物的读者,可以先看看这篇文章《 【玩转 .Net MF 06 】为 Cortex-M3 打造轻量级 TinyGUI (上) 》。

TinyGUI 接口非常简单,相关声明如下:

public sealed class Graphics

{

public Graphics();

public static void Clear( uint color);

public static void DrawEllipse( int x, int y, int width, int height, uint color);

public static void DrawImage( int x, int y, byte [] bytData);

public static void DrawImageEx( int x, int y, byte [] bytData, uint MaskColor);

public static void DrawLine( int x1, int y1, int x2, int y2, uint color);

public static void DrawRectangle( int x, int y, int width, int height, uint color);

public static void DrawString( int x, int y, string s, uint color);

public static void FillEllipse( int x, int y, int width, int height, uint color);

public static void FillRectangle( int x, int y, int width, int height, uint color);

public static uint GetPixel( int x, int y);

public static void Print( string str);

public static void SetPixel( int x, int y, uint color);

}

相关绘图示例如下(这就是我以前提供图形示例 pe 文件的源码)

public static void Main()

{

uint [] colors = new uint []{ Color .Black, Color .Red, Color .Green, Color .Orange, Color .Yellow, Color .Brown, Color .Purple, Color .Gray,

Color .DarkGray, Color .LightGray, Color .Blue, Color .Magenta, Color .Cyan, Color .White, Color .LightGreen};

Graphics .Clear( Color .Blue);

int x, y, width, height,c;

long index = 0;

Random rnd = new Random ();

while ( true )

{

x = rnd.Next(239);

width = rnd.Next(239 - x);

y = rnd.Next(319);

height = rnd.Next(319 - y);

c = rnd.Next(colors.Length-1);

switch (index % 3)

{

case 0:

if (rnd.Next(10) > 5)

Graphics .DrawRectangle(x, y, width, height, colors[c]);

else

Graphics .FillRectangle(x, y, width, height, colors[c]);

break ;

case 1:

if (rnd.Next(10) > 5)

Graphics .DrawEllipse(x, y, width, height, colors[c]);

else

Graphics .FillEllipse(x, y, width, height, colors[c]);

break ;

case 2:

Graphics .DrawLine(x, y, rnd.Next(239), rnd.Next(319), colors[c]);

break ;

}

Graphics .FillRectangle(0, 300, 239, 19, Color .White);

Graphics .DrawString(2, 303, (index++).ToString(), Color .Blue);

Thread .Sleep(50);

}

}

代码比较简单,这里我就不过多解释了。需要说明的是,该程序不能直接在模拟器中运行,并且需要引用 System.TinyGUI.dll 库。

运行后的结果如下:

【STM32 .Net MF开发板学习-03】TinyGUI绘图示例

至于如何制作和显示 TinyBMP 格式的位图我们下篇文章再进行介绍。

-----------------------------------------------------------------------------------------

源码下载: http://www.sky-walker.com.cn/yefan/MFV40/SourceCode/TinyGUI_Sample.rar

相关链接:《 免费发放 firmwave ,打造史上最低价 .Net MF 开发板

.Net Micro Framework 快速入门

中文讨论组: http://space.cnblogs.com/group/MFSoft/

【STM32 .Net MF开发板学习-03】TinyGUI绘图示例


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论