簡體   English   中英

UINT8中的自定義符號 - 如何轉換為C#?

[英]Custom Symbol in UINT8 - how to convert to C#?

我有以下符號,這是一個! 用C ++編寫:

const UINT8 ras[1][28] ={ {0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00} }; //'!'

現在,我需要在C#中將其創建為符號並將其打印在控制台或圖像上,這怎么可能?

我知道應該打印一個! 但是,我如何從陣列到達!!

這看起來像一個16x14像素的位圖。 如果我們將兩個字節取兩個字節,我們得到:

0x00, 0x00,
0x30, 0x00,
0x30, 0x00,
0x00, 0x00,
0x00, 0x00,
0x30, 0x00,
0x30, 0x00,
0x30, 0x00,
0x30, 0x00,
0x30, 0x00,
0x30, 0x00,
0x30, 0x00,
0x30, 0x00,
0x00, 0x00

現在,值0x30的二進制模式是00110000 ,因此它看起來像一個帶有2x2像素點的驚嘆號,和一個2x8像素的垂直部分,就像這樣(保留最左邊的字節,因為最右邊)在每一行是0或空白):

00000000
00110000
00110000
00000000
00000000
00110000
00110000
00110000
00110000
00110000
00110000
00110000
00110000
00000000

顯然,它也是倒掛的。 使用上面的信息,您應該能夠創建一個普通的舊Bitmap並對其進行初始化,以便獲得最終在C#中顯示的內容。 當然,對於這個非常簡單的圖像來說,這聽起來有些繞圈,但是仍然如此。

要初始化Bitmap,您可以執行以下操作:

byte[] input = new byte[] { 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00 };

glyph = new Bitmap(16, 14, System.Drawing.Imaging.Format1bppIndexed);
for(int y = 0; y < glyph.Height; y++)
{
  int input_y = (glyph.Height - 1) - y; // Flip it right side up.
  for(int x = 0; x < glyph.Width; x++)
  {
    bool on = input[2 * input_y + x / 8] & (0x80 >> (x % 8));
    glyph.SetPixel(x, y, on ? System.Drawing.Color.Black : System.Drawing.Color.White);
  }
}

請注意,這段代碼非常粗糙,我真的不是C#開發人員。 將其視為偽代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM