Search code examples
windowsgraphicsgdiargbdib

Create ARGB DIB


How to create a DIB with ARGB format. I want to blit a image(that has some part transparent in it ) using this DIB. I tried with the following code but its not working properly

   unsigned char * rawdata;   ==> Filled by Qimage Raw Data
    unsigned char * buffer = NULL;  
    memset(&bmi, 0, sizeof(bmi));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = width;/* Width of your image buffer */
    bmi.bmiHeader.biHeight = -height; /* Height of your image buffer */
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;
   HBITMAP  g_dibbmp = CreateDIBSection(hDesktopDC, &bmi, DIB_RGB_COLORS, (void **)&buffer, 0, 0);
    if (!buffer) 
    { /* ERROR */
        printf("ERROR DIB could not create buffer\n");
    }
    else
    {
        printf("DIB created buffer successfully\n");
        memcpy(buffer,rawdata,sizeof(rawdata));
    }

Please help.

Reagards,

Techtotie.


Solution

  • Thanks for your answer.

    But my problem got solved. It was not actually the problem with the DIB creation. It was due to the wrong API that I was using for Blitting.

    I was using BitBlt for blitting but this API does not take care of the Alpha gradient. Instead of it I tried TransparentBlt (Refer : http://msdn.microsoft.com/en-us/library/windows/desktop/dd145141(v=vs.85).aspx)

    and it worked as this API takes care of copying the Alpha values from Source DC to destination DC.