简体   繁体   中英

Custom Symbol in UINT8 - how to convert to C#?

I have the following symbol which is a ! written in 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} }; //'!'

Now I need to create this in C# as a symbol and print it on a console or image, how is that possible?

I know it is supposed to print a !. But how do I got from my array to !?

This looks like a 16x14-pixel bitmap. If we take the bytes two by two, we get:

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

Now, the binary pattern for the value 0x30 is 00110000 , so it looks like an exclamation point with a 2x2-pixel dot, and a 2x8-pixel vertical part, like so (keeping only the left-most byte, since the right-most on each line is 0 or blank):

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

Obviously, it's also up-side down. Using the above information, you should be able to create eg a plain old Bitmap and initialize it so you get something you eventually display in C#. Of course, that sounds a bit round-about for this very simplistic image, but still.

To initialize the Bitmap, you would do something like:

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);
  }
}

Note that this code is very rough, I'm really not a C# developer. Treat it as pseudo-code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM