创建一个从二进制数据位图 [英] Create bitmap from binary data
本文介绍了创建一个从二进制数据位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
byte[] pixels = new byte[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 };
这是一个颠倒的感叹号是这样的:
This is an upside down exclamation mark like this:
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
这二进制是:
00000000 00000000
00110000 00000000
00110000 00000000
00000000 00000000
00000000 00000000
00110000 00000000
00110000 00000000
00110000 00000000
00110000 00000000
00110000 00000000
00110000 00000000
00110000 00000000
00110000 00000000
00000000 00000000
我需要将其转换为位图/创建位图。所以感叹号是白色的,背景是黑色的。我需要能够到彩色像素也。
I need to convert this to a bitmap / create a bitmap. So the exclamation mark is white and the background is black. I need to be able to color the pixels also.
如何做到这一点?
推荐答案
假设所有的图像是16x14
Assuming all your images are 16x14
Bitmap bmp = new Bitmap(16, 14);
int line=0;
for (int i = 0; i < pixels.Length; i++)
{
for (int j = 0; j<8; j++)
{
if (((pixels[i] >> j) & 1) == 1)
{
bmp.SetPixel( (i%2)*8 + 7-j, line, Color.Black);
}
}
if(i%2==1) line++;
}
这篇关于创建一个从二进制数据位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文