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]);
Graphics.FillEllipse(x, y, width, height, colors[c]);
case 2:
Graphics.DrawLine(x, y, rnd.Next(239), rnd.Next(319), colors[c]);
}
Graphics.FillRectangle(0, 300, 239, 19, Color.White);
Graphics.DrawString(2, 303, (index++).ToString(), Color.Blue);
Thread.Sleep(50);
}
}
代碼比較簡單,這裡我就不過多解釋了。需要說明的是,該程式不能直接在模拟器中運作,并且需要引用System.TinyGUI.dll庫。
運作後的結果如下:
至于如何制作和顯示TinyBMP格式的位圖我們下篇文章再進行介紹。
-----------------------------------------------------------------------------------------