Convert BITMAPINFO header into unsigned char pointer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Convert BITMAPINFO header into unsigned char pointer

  1. #1
    Join Date
    Aug 2012
    Posts
    53

    Convert BITMAPINFO header into unsigned char pointer

    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.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    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
    Location
    Voronezh, Russia
    Posts
    6,070

    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 06:33 AM.
    Best regards,
    Igor

  4. #4
    Join Date
    Aug 2012
    Posts
    53

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center