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/
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
