如何将十六进制值转换为visual cpp中的位图图像? [英] How to convert the hex value into bitmap image in visual cpp?

查看:67
本文介绍了如何将十六进制值转换为visual cpp中的位图图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6位十六进制数组,我希望将其转换为cpp中的BMP。

请你分享答案。




我尝试过:



i只有6位十六进制数组。

i have the 6 digit hexadecimal array i want convert it into BMP in cpp.
can you please share the answers.


What I have tried:

i have array of 6 digit hexadecimals only.

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

static const char alphanum[] =
"0123456789"
"abcdef";

int stringLength = sizeof(alphanum) - 1;
char genRandom()
{
	return alphanum[rand() % stringLength];
}

int main()
{
	srand(time(0));
	std::string Str;
	for (int j = 0; j < 8; j++)
	{
		for (unsigned int i = 0; i < 6; ++i)
		{
			Str += genRandom();
		}
		cout << Str << endl;
		Str = "\0";

	}
}

推荐答案

更简单的部分是转换数字的十六进制字符串表示形式到实际的字节。例如,您可以使用 strtol

如果我找到你,那么更复杂的部分是实际创建的有效Bitmap。幸运的是,网上有示例代码。比如看(我没有测试过)创建位图bmp文件像素数据| technical-recipes.com [ ^ ]。
The simpler part is converting the hexadecimal string representation of the numbers into actual bytes. You could use strtol, for instance.
The more complex part, if I got you, is the actual creation of a valid Bitmap. Luckily there is sample code on the web. See, for instance (I've not tested it) Create a bitmap bmp file pixel data | technical-recipes.com[^].


这篇关于如何将十六进制值转换为visual cpp中的位图图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆