By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,136 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,136 IT Pros & Developers. It's quick & easy.

Bitmap to Hexadecimal conversion

P: 12
Hello All,

I need to convert the bitmap image to hexadecimal, so is there any free tool for doing this conversion? Any other suggestion is always welcome.

Thank you in advance.

Regards,
Pramod
Dec 22 '06 #1
Share this Question
Share on Google+
10 Replies


100+
P: 145
Hello All,

I need to convert the bitmap image to hexadecimal, so is there any free tool for doing this conversion? Any other suggestion is always welcome.

Thank you in advance.

Regards,
Pramod
Do you mean to output the pixel values in hex?

You could use my EasyBMP C++ BMP library. It's free and open source. Here's how you would get at the individual pixel values:

Expand|Select|Wrap|Line Numbers
  1. #include "EasyBMP.h"
  2.  
  3. // ... 
  4.  
  5. BMP Image;
  6. Image.ReadFromFile( "SomePicture.bmp" );
  7.  
  8. for( int j=0 ; j < Image.TellHeight() ; j++ )
  9. {
  10.  for( int i=0; i < Image.TellWidth() ; i++ )
  11.  {
  12.   cout << "red: " << Image(i,j)->Red << "\t"
  13.        << "green: " << Image(i,j)->Green << "\t"
  14.        << "blue: " << Image(i,j)->Blue << endl;
  15.  }
  16. }
  17.  
The red, green, and blue values are of type ebmpBYTE, which are essentially unsigned chars ranging from 0 to 255. You'd be free to convert those to hex or whatever you like as you see fit. (And I'm sure you'd have people who are willing to help determine the conversion.) I suppose that the color (255,0,0) would appear as

0xff0000,

the color (16,32,254) would be

0x1020fe,

etc. Please let me know if this is the sort of thing you are trying to do. Thanks -- Paul
Dec 22 '06 #2

100+
P: 145
To come to think of it, this modification should do the trick:

Expand|Select|Wrap|Line Numbers
  1. cout << "pixel (" << i << "," << j << "): " 
  2.      << hex << Image(i,j)->Red << 
  3.      << hex << Image(i,j)->Green << 
  4.      << hex << Image(i,j)->Blue << endl;
  5.  
Thanks -- Paul
Dec 22 '06 #3

P: 12
Do you mean to output the pixel values in hex?

You could use my EasyBMP C++ BMP library. It's free and open source. Here's how you would get at the individual pixel values:

Expand|Select|Wrap|Line Numbers
  1. #include "EasyBMP.h"
  2.  
  3. // ... 
  4.  
  5. BMP Image;
  6. Image.ReadFromFile( "SomePicture.bmp" );
  7.  
  8. for( int j=0 ; j < Image.TellHeight() ; j++ )
  9. {
  10.  for( int i=0; i < Image.TellWidth() ; i++ )
  11.  {
  12.   cout << "red: " << Image(i,j)->Red << "\t"
  13.        << "green: " << Image(i,j)->Green << "\t"
  14.        << "blue: " << Image(i,j)->Blue << endl;
  15.  }
  16. }
  17.  
The red, green, and blue values are of type ebmpBYTE, which are essentially unsigned chars ranging from 0 to 255. You'd be free to convert those to hex or whatever you like as you see fit. (And I'm sure you'd have people who are willing to help determine the conversion.) I suppose that the color (255,0,0) would appear as

0xff0000,

the color (16,32,254) would be

0x1020fe,

etc. Please let me know if this is the sort of thing you are trying to do. Thanks -- Paul

Hello Paul,

Thankyou for the feedback.

Actually i was looking for conversion from a bitmap image to its equivalent hexadecimal numbers.
Eg: like from image.bmp to its hexadecimal format

Thank you in advance.

Regards,
Pramod
Dec 26 '06 #4

100+
P: 145
Hello Paul,

Thankyou for the feedback.

Actually i was looking for conversion from a bitmap image to its equivalent hexadecimal numbers.
Eg: like from image.bmp to its hexadecimal format

Thank you in advance.

Regards,
Pramod
I'm afraid I don't understand. A bitmap image is in binary to begin with. hex is just a matter of how you view the data. -- Paul
Dec 26 '06 #5

P: 12
I'm afraid I don't understand. A bitmap image is in binary to begin with. hex is just a matter of how you view the data. -- Paul
Hello,

Actually i have got an bitmap image and i need to convert this into a icon for me to use it in my application. On edit on this icon as text format i will obtain it in hexa decimal format.

So either i need to convert this bitmap to icon or to its hexadecimal equivalent. Its better for me to have it in hex format as i need to copy this on to the existing icon.

Rgds,
Pramod
Dec 26 '06 #6

100+
P: 145
Hello,

Actually i have got an bitmap image and i need to convert this into a icon for me to use it in my application. On edit on this icon as text format i will obtain it in hexa decimal format.

So either i need to convert this bitmap to icon or to its hexadecimal equivalent. Its better for me to have it in hex format as i need to copy this on to the existing icon.

Rgds,
Pramod
What are the dimensions of the image? Also, do you need it in reduced color? (4 or 8 bits per pixel) Lastly, do you need only the image pixels, or the entire .ico data structure? I'm just trying to understand what it is you actually need.

Thanks -- Paul
Dec 26 '06 #7

P: 12
What are the dimensions of the image? Also, do you need it in reduced color? (4 or 8 bits per pixel) Lastly, do you need only the image pixels, or the entire .ico data structure? I'm just trying to understand what it is you actually need.

Thanks -- Paul

Hello,

I have a bitmap image (width=154 and height=124), units=pixel and this one i need to convert into an icon so i can use it in resource workshop. After conversion, the icon should be in 32*32 size, 16 colors and in hexa decimal format like
'00 00 01 00 01 00 20 20 10 00 00 00 00 00 E8 02'
'00 00 16 00 00 00 28 00 00 00 20 00 00 00 40 00' etc

So if i copy this hexadecimal format in resource workshop, i should be able to reproduce the earlier same bitmap image but now as an icon.
Suggest me if i can do the same in any other way.

Hope i am clear here. Thank you in advance.

Rgds,
Pramod
Dec 27 '06 #8

P: 6
If you want just the file as hex, its a simple process:

Open File
Do Until EOF
Read Section of File into buffer
For i=0 to length of buffer
Output byte[i] of buffer as hex
Next
Loop
Close File

If you actually want to translate the file into something meaningful then you will have to specify what file format the image is in. You cannot simply spit out RGB, all graphic file formats are very different, some use compression others do not.

If you want to convert the graphic to an icon, simply load the graphic, copy to the clipboard, then load you icon editor and paste image from the clipboard. Resize and save as ico file.
Dec 27 '06 #9

100+
P: 145
Note that the .ico file format is slightly different than the .bmp file format, so spitting it out in hex isn't enough.

Also, note that your image is not square, so resizing it to 32 x 32 will involve some distortion. -- Paul
Dec 27 '06 #10

P: n/a
good work
Oct 17 '10 #11

Post your reply

Sign in to post your reply or Sign up for a free account.