• 让TinyGUI库支持模拟器


    Microsoft .Net Micro Framework 官方UI库为WPF,针对320*240的LCD而言,至少额外需要150K以上RAM才能基本运行,所以推出了轻量级的图形库TinyGUI。

    WPF支持标准BMP,JPG,GIF图片显示,从使用角度来看非常方便,但是由于嵌入式LCD大都为16bit显示(RGB565格式),无论是BMP还是JPG和GIF都需要进行颜色转换,此外后者还需要进行格式转换处理。以上操作,不仅导致运行速度慢,还需要一定的内存进行图形缓存。

    TinyGUI的位图显示采用转换后的tinyBMP位图格式,其格式和LCD显存格式保持一致,由于图形转换工作通过工具YFTBConvert预先完成,所以在嵌入式系统上直接向显存拷贝,即可完成位图显示,所以运行速度极快。

    第一个版本的库,不支持模拟器显示,这样用户在测试新应用时,必须借助实际的开发板才能看到实际的运行效果,这大大影响了用户的体验,所以重新设计了代码,让模拟器也能支持TinyGUI库的运行。

    在《TinyGUI绘图示例》中我们介绍过TinyGUI的使用,当时的库还只能在开发板中运行,现在同样的示例代码,我们让其在模拟器中运行,示例代码如下:

    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;

        HardwareProvider hwp = new HardwareProvider();

        int lcd_width,lcd_height,lcd_bitsPerPixel,lcd_orientationDeg;

        hwp.GetLCDMetrics(out lcd_width, out lcd_height, out lcd_bitsPerPixel, out lcd_orientationDeg);           

        int Graphics_Width = lcd_width - 1;

        int Graphics_Height = lcd_height - 1;

        Random rnd = new Random();

        while (true)

        {

            x = rnd.Next(Graphics_Width);

            width = rnd.Next(Graphics_Width - x);

            y = rnd.Next(Graphics_Height);

            height = rnd.Next(Graphics_Height - 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(Graphics_Width), rnd.Next(Graphics_Height), colors[c]);

                    break;

            }

            Graphics.FillRectangle(0, Graphics_Height-19, Graphics_Width, 19, Color.White);

            Graphics.DrawString(2, Graphics_Height-17, (index++).ToString(), Color.Blue);

            Thread.Sleep(50);

        }

    }

      在模拟器中运行的效果图如下(其实在官方模拟器中也可以运行)。

      红牛模拟器下载:http://blog.csdn.net/yefanqiu/archive/2011/02/27/6212071.aspx

     

     System.TinyGUI库的下载地址如下(包含文档和示例代码):

    http://www.sky-walker.com.cn/MFRelease/library/System.TinyGUI.rar 

    附:System.TinyGUI库函数说明

    1.1 Clear

    声明:void Clear(uint color)

    参数:color– 清除后的背景色 (24bit RGB)

    返回: 

    说明: 以用指定颜色清除LCD显示。

    1.2 SetPixel

    声明:void SetPixel(int x,int y,uint color)

    参数:x,y – 屏幕坐标

          color– 颜色

    返回:

    说明: 画点。

    1.3 GetPixel

    声明:uint GetPixel (int x,int y)

    参数:x,y – 屏幕坐标

    返回:指定坐标的颜色

    说明:返回指定坐标的颜色,有些硬件不支持该函数。

    1.4 DrawLine

    声明:void DrawLine(int x1, int y1, int x2, int y2, uint color)

    参数:x1,y1,x2,y2 – 屏幕坐标

    color– 颜色

    返回:

    说明:画线。

    1.5 DrawRectangle

    声明:void DrawRectangle(int x, int y, int width, int height, uint color)

    参数:x,y – 屏幕左上角坐标

          width,height – 宽,高

    color– 颜色

    返回:

    说明:画空心矩形。

    1.6 DrawEllipse

    声明:void DrawEllipse(int x, int y, int width,int height, uint color)

    参数:x,y – 屏幕左上角坐标

          width,height – 宽,高

    color– 颜色

    返回:

    说明:画空心椭圆。

    1.7 DrawImage

    声明:void DrawImage(int x, int y, byte[] bytData)

    参数:x,y – 屏幕左上角坐标

          bytData - TinyBMP格式的图像数据

    返回:

    说明:位图绘制(模拟器暂不支持)。

    1.8 DrawImageEx

    声明:void DrawImageEx (int x, int y, byte[] bytData,uint MaskColor)

    参数:x,y – 屏幕左上角坐标

          bytData - TinyBMP格式的图像数据

    MaskColor– 屏蔽色

    返回:

    说明:位图绘制(模拟器暂不支持)。

    1.9 DrawString

    声明:void DrawString (int x, int y,string s, uint color)

    参数:x,y – 屏幕左上角坐标

          s – 字符串

    color– 字体颜色

    返回:

    说明:绘制字体(暂时仅支持符号和西文字符)

    1.10 FillRectangle

    声明:void FillRectangle (int x, int y, int width, int height, uint color)

    参数:x,y – 屏幕左上角坐标

          width,height – 宽,高

    color– 填充色

    返回:

    说明:画填充矩形。

    1.11 FillEllipse

    声明:void FillEllipse (int x, int y, int width, int height, uint color)

    参数:x,y – 屏幕左上角坐标

          width,height – 宽,高

    color– 填充色

    返回:

    说明:画填充椭圆。

    1.12 Print

    声明:void Print(string str)

    参数:str – LCD显示的字符串

    返回:

    说明:LCD信息输出(底层LCD_Printf函数的封装)。

    1.13 SuspendLayout

    声明:void SuspendLayout ()

    参数:

    返回:

    说明:挂起LCD的输出显示。

    1.14 ResumeLayout

    声明:void SuspendLayout ()

    参数:

    返回:

    说明:恢复挂起的LCD输出显示。

    MF快速参考: .NET Micro Framework 快速入门

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

    【低价开发板】http://item.taobao.com/item.htm?id=7117999726

  • 相关阅读:
    实验一、词法分析实验
    词法分析程序新
    词法分析程序
    我对编译原理的理解
    Unity3d数据存储 PlayerPrefs,XML,Json数据的存储与解析
    Unity3d网络总结(三) 封装Socket创建简单网络
    Unity3d网络总结(二)使用NetWorking代码搭建简单的网络模块
    Unity3d网络总结(一) NetWork组件使用
    Unity加载AB包
    unity编辑器拓展
  • 原文地址:https://www.cnblogs.com/yefanqiu/p/1969420.html
Copyright © 2020-2023  润新知