CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012

    Convert BITMAPINFO header into unsigned char pointer

    Hey there,

    I have a bitmap header information in the struct

    typedef struct tagBITMAPINFO {
    RGBQUAD bmiColors[1];

    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.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003

    Re: Convert BITMAPINFO header into unsigned char pointer

    You want to make a buffer big enough to hold the header and the bits, then use memcpy to copy the header and the image into the new buffer.

  3. #3
    Join Date
    Nov 2000
    Voronezh, Russia

    Re: Convert BITMAPINFO header into unsigned char pointer

    Please note the bmiColors[1]. This is where your raw data should start when copied to the new buffer. This trick is widely used in Win32 API when reference to a data of variable size is provided.

    Besides, be careful about wording. The word 'convert' is not appropriate here. You cannot convert buffer to a pointer, as this makes no sense: buffer/structure is a memory bytes, pointer is a memory address. Using incorrect terminology typically leads to lots of misunderstandings as well as obscuring the essence of the issue, and inability to solve it proper way as the result.
    Last edited by Igor Vartanov; January 11th, 2014 at 05:33 AM.
    Best regards,

  4. #4
    Join Date
    Aug 2012

    Re: Convert BITMAPINFO header into unsigned char pointer

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.