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

简介: .Net Micro Framework官方图形库是WPF,由于目前ST Cortex-M3开发板RAM太小,最大才512K(常见是128K或256k),并且Cortex-M3的CPU主频也不太高,运行WPF图形框架显得过于重了,所以我这边推出了轻量级图形库TinyGUI

源码下载:http://www.sky-walker.com.cn/yefan/MFV40/SourceCode/TinyGUI_Sample.rar
文章参考: 《.Net Micro Framework 快速入门》
中文讨论组:http://space.cnblogs.com/group/MFSoft/

.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);

    }
AI 代码解读

相关绘图示例如下(这就是我以前提供图形示例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);

            }

         }
AI 代码解读

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

运行后的结果如下:

image.png

 

至于如何制作和显示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/

目录
打赏
0
0
0
0
4751
分享
相关文章
|
8月前
|
API
【Azure 媒体服务】Media Service的编码示例 -- 创建缩略图子画面的.NET代码调试问题
【Azure 媒体服务】Media Service的编码示例 -- 创建缩略图子画面的.NET代码调试问题
stm32f407探索者开发板(二十二)——通用定时器基本原理讲解
stm32f407探索者开发板(二十二)——通用定时器基本原理讲解
941 0
|
9月前
stm32f407探索者开发板(十九)——外部中断实验-EXIT
stm32f407探索者开发板(十九)——外部中断实验-EXIT
629 0
【Azure Developer】.Net 简单示例 "文字动图显示" Typing to SVG
【Azure Developer】.Net 简单示例 "文字动图显示" Typing to SVG
【Azure Developer】.Net 简单示例 "文字动图显示" Typing to SVG
|
9月前
stm32f407探索者开发板(二十三)——定时器中断实验
stm32f407探索者开发板(二十三)——定时器中断实验
972 0
stm32f407探索者开发板(二十一)——窗口看门狗
stm32f407探索者开发板(二十一)——窗口看门狗
357 0
|
9月前
|
stm32f407探索者开发板(二十)——独立看门狗实验
stm32f407探索者开发板(二十)——独立看门狗实验
493 0
|
9月前
|
stm32f407探索者开发板(十八)——串口通信实验讲解(USART_RX_STA流程图详解)
stm32f407探索者开发板(十八)——串口通信实验讲解(USART_RX_STA流程图详解)
807 0
|
10月前
使用STM32F103标准库实现定时器控制LED点亮和关闭
通过这篇博客,我们学习了如何使用STM32F103标准库,通过定时器来控制LED的点亮和关闭。我们配置了定时器中断,并在中断处理函数中实现了LED状态的切换。这是一个基础且实用的例子,适合初学者了解STM32定时器和中断的使用。 希望这篇博客对你有所帮助。如果有任何问题或建议,欢迎在评论区留言。
764 2
|
9月前
stm32f407探索者开发板(十七)——串口寄存器库函数配置方法
stm32f407探索者开发板(十七)——串口寄存器库函数配置方法
1199 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等