.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 庫。
運行后的結果如下:
至于如何制作和顯示 TinyBMP 格式的位圖我們下篇文章再進行介紹。
-----------------------------------------------------------------------------------------
源碼下載: http://www.sky-walker.com.cn/yefan/MFV40/SourceCode/TinyGUI_Sample.rar
相關鏈接:《 免費發放 firmwave ,打造史上最低價 .Net MF 開發板 》
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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