Click here to Skip to main content
15,066,496 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C++
#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";

	}
}
Posted
Updated 9-Aug-18 5:14am
v2

1 solution

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[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900