从二进制数据创建位图
我有以下内容:
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 };
这是一个颠倒的感叹号,如下所示:
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 have the following:
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
Which in binary is:
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.
How to do this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设所有图像都是 16x14
Assuming all your images are 16x14
考虑阅读有关 BMP 格式的维基百科。您将需要它来确保您的数组包含必要的元数据(例如宽度和高度)。进行这些更改后,您可以使用类似的东西
Consider reading Wikipedia about BMP format. You will need this to make sure that your array contains necessary meta data (e.g width and height). After making those changes you can use something like this
据我了解,您想要创建一个与字节数组(您的“感叹号”)内的内容类似的位图。
您可以从头开始创建位图,并使用一些循环,只需在位图中设置像素即可。这是一个在黑色背景上绘制随机白色像素的简单示例。对其进行调整以满足您的要求:
From what I understand, you want to create a bitmap that looks similar to what's inside your byte array (your "exclamation mark").
You can create a bitmap from scratch, and using some loops, simply set pixels in your
Bitmap
. Here's a simple example that draws random white pixels on a black background. Adapt it to meet your requirements: