Bitmap to Hexadecimal conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pramod Kadur
    New Member
    • Dec 2006
    • 12

    Bitmap to Hexadecimal conversion

    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
  • macklin01
    New Member
    • Aug 2005
    • 145

    #2
    Originally posted by Pramod Kadur
    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:

    Code:
    #include "EasyBMP.h"
    
    // ... 
    
    BMP Image;
    Image.ReadFromFile( "SomePicture.bmp" );
    
    for( int j=0 ; j < Image.TellHeight() ; j++ )
    {
     for( int i=0; i < Image.TellWidth() ; i++ )
     {
      cout << "red: " << Image(i,j)->Red << "\t"
           << "green: " << Image(i,j)->Green << "\t"
           << "blue: " << Image(i,j)->Blue << endl;
     }
    }
    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

    Comment

    • macklin01
      New Member
      • Aug 2005
      • 145

      #3
      To come to think of it, this modification should do the trick:

      Code:
      cout << "pixel (" << i << "," << j << "): " 
           << hex << Image(i,j)->Red << 
           << hex << Image(i,j)->Green << 
           << hex << Image(i,j)->Blue << endl;
      Thanks -- Paul

      Comment

      • Pramod Kadur
        New Member
        • Dec 2006
        • 12

        #4
        Originally posted by macklin01
        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:

        Code:
        #include "EasyBMP.h"
        
        // ... 
        
        BMP Image;
        Image.ReadFromFile( "SomePicture.bmp" );
        
        for( int j=0 ; j < Image.TellHeight() ; j++ )
        {
         for( int i=0; i < Image.TellWidth() ; i++ )
         {
          cout << "red: " << Image(i,j)->Red << "\t"
               << "green: " << Image(i,j)->Green << "\t"
               << "blue: " << Image(i,j)->Blue << endl;
         }
        }
        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

        Comment

        • macklin01
          New Member
          • Aug 2005
          • 145

          #5
          Originally posted by Pramod Kadur
          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

          Comment

          • Pramod Kadur
            New Member
            • Dec 2006
            • 12

            #6
            Originally posted by macklin01
            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

            Comment

            • macklin01
              New Member
              • Aug 2005
              • 145

              #7
              Originally posted by Pramod Kadur
              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

              Comment

              • Pramod Kadur
                New Member
                • Dec 2006
                • 12

                #8
                Originally posted by macklin01
                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

                Comment

                • SimonPlatten
                  New Member
                  • Dec 2006
                  • 6

                  #9
                  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.

                  Comment

                  • macklin01
                    New Member
                    • Aug 2005
                    • 145

                    #10
                    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

                    Comment

                    • quick post

                      #11
                      good work

                      Comment

                      Working...