简体   繁体   English

UINT8中的自定义符号 - 如何转换为C#?

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

I have the following symbol which is a ! 我有以下符号,这是一个! written in 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} }; //'!'

Now I need to create this in C# as a symbol and print it on a console or image, how is that possible? 现在,我需要在C#中将其创建为符号并将其打印在控制台或图像上,这怎么可能?

I know it is supposed to print a !. 我知道应该打印一个! But how do I got from my array to !? 但是,我如何从阵列到达!!

This looks like a 16x14-pixel bitmap. 这看起来像一个16x14像素的位图。 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): 现在,值0x30的二进制模式是00110000 ,因此它看起来像一个带有2x2像素点的惊叹号,和一个2x8像素的垂直部分,就像这样(保留最左边的字节,因为最右边)在每一行是0或空白):

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#. 使用上面的信息,您应该能够创建一个普通的旧Bitmap并对其进行初始化,以便获得最终在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: 要初始化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);
  }
}

Note that this code is very rough, I'm really not a C# developer. 请注意,这段代码非常粗糙,我真的不是C#开发人员。 Treat it as pseudo-code. 将其视为伪代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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