Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert BITMAPINFO into a unsigned char pointer

Convert BITMAPINFO into a unsigned char pointer

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Don Guy
    wrote on last edited by
    #1

    Hey there, I have a bitmap header information in the struct typedef struct tagBITMAPINFO { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1]; } BITMAPINFO The total size of this is 1080. Now i want to convert this into a unsigned char pointer. unsigned char * pBMPHeaderData; I already got the raw image data in another unsigned char buffer. unsigned char* pRawBMPData; Now i want to make a complete BMP image by adding the header info and raw data into a new unsigned char pointer. For this i need to convert the BITMAPINFO struct into a unsigned char * So the new buffer will be, unsigned char * pCompleteBMPIMageData = pBMPHeaderData + pRawBMPData; Can anyone tell me how to do this? Thanks in advance.

    J L 2 Replies Last reply
    0
    • D Don Guy

      Hey there, I have a bitmap header information in the struct typedef struct tagBITMAPINFO { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1]; } BITMAPINFO The total size of this is 1080. Now i want to convert this into a unsigned char pointer. unsigned char * pBMPHeaderData; I already got the raw image data in another unsigned char buffer. unsigned char* pRawBMPData; Now i want to make a complete BMP image by adding the header info and raw data into a new unsigned char pointer. For this i need to convert the BITMAPINFO struct into a unsigned char * So the new buffer will be, unsigned char * pCompleteBMPIMageData = pBMPHeaderData + pRawBMPData; Can anyone tell me how to do this? Thanks in advance.

      J Offline
      J Offline
      Jonathan Davies
      wrote on last edited by
      #2

      Have a look at CreateDIBSection http://msdn.microsoft.com/en-us/library/windows/desktop/dd183494(v=vs.85).aspx[^] this can be used to combine BITMPAINFOHEADER data and the actual bits. Though I realise this doesn't actually give you a char pointer it may be something you can use.

      1 Reply Last reply
      0
      • D Don Guy

        Hey there, I have a bitmap header information in the struct typedef struct tagBITMAPINFO { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1]; } BITMAPINFO The total size of this is 1080. Now i want to convert this into a unsigned char pointer. unsigned char * pBMPHeaderData; I already got the raw image data in another unsigned char buffer. unsigned char* pRawBMPData; Now i want to make a complete BMP image by adding the header info and raw data into a new unsigned char pointer. For this i need to convert the BITMAPINFO struct into a unsigned char * So the new buffer will be, unsigned char * pCompleteBMPIMageData = pBMPHeaderData + pRawBMPData; Can anyone tell me how to do this? Thanks in advance.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        What do you mean by "i want to convert this into a unsigned char pointer."? A pointer is merely the address of some block of memory, you do not convert things into pointers. Procedurally to combine the two blocks into a new BMP you need to do the following:

        // BYTE is a Windows typedef for unsigned char, and generally makes your purpose clearer
        // PBYTE is a typedef for a BYTE*
        PBYTE pCompleteBMPIMageData = new BYTE[size of header plus size of raw data];
        memcpy(pCompleteBMPIMageData, reinterpret_cast(&BITMAPINFO), sizeof BITMAPINFO);
        memcpy(pCompleteBMPIMageData + sizeof BITMAPINFO, pRawBMPData, size of raw data);

        Veni, vidi, abiit domum

        D 1 Reply Last reply
        0
        • L Lost User

          What do you mean by "i want to convert this into a unsigned char pointer."? A pointer is merely the address of some block of memory, you do not convert things into pointers. Procedurally to combine the two blocks into a new BMP you need to do the following:

          // BYTE is a Windows typedef for unsigned char, and generally makes your purpose clearer
          // PBYTE is a typedef for a BYTE*
          PBYTE pCompleteBMPIMageData = new BYTE[size of header plus size of raw data];
          memcpy(pCompleteBMPIMageData, reinterpret_cast(&BITMAPINFO), sizeof BITMAPINFO);
          memcpy(pCompleteBMPIMageData + sizeof BITMAPINFO, pRawBMPData, size of raw data);

          Veni, vidi, abiit domum

          D Offline
          D Offline
          Don Guy
          wrote on last edited by
          #4

          The reason why i want to get the BITMAP Info structure in a unsigned char pointer is because i want to convert that into a base64 encoded string. So it's not about converting a structure into a unsigned char pointer. I want the data in the structure to be populated in a unsigned char pointer so that it could be later used to generate a base64 encoded string for the bitmap image.

          L C 2 Replies Last reply
          0
          • D Don Guy

            The reason why i want to get the BITMAP Info structure in a unsigned char pointer is because i want to convert that into a base64 encoded string. So it's not about converting a structure into a unsigned char pointer. I want the data in the structure to be populated in a unsigned char pointer so that it could be later used to generate a base64 encoded string for the bitmap image.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Well if you use my suggested code, that is what you will get.

            Veni, vidi, abiit domum

            1 Reply Last reply
            0
            • D Don Guy

              The reason why i want to get the BITMAP Info structure in a unsigned char pointer is because i want to convert that into a base64 encoded string. So it's not about converting a structure into a unsigned char pointer. I want the data in the structure to be populated in a unsigned char pointer so that it could be later used to generate a base64 encoded string for the bitmap image.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Richard gave you the right suggestion, then. The only trick part is computing the size of the raw data (you may find sample code at MSDN[^]). Please note, as workaround, you could directly encode the whole BMP file (if you have it) content in Base64.

              Veni, vidi, vici.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups