Search code examples
bitmapalphabitmapdata

Is there a way to change the alpha of a 24-bit bitmap image using a byte field?


I am trying to do this by adjusting the hexadecimal values of the bitmap image however as far as I can tell there is no alpha byte. Would I be able to adjust the format of the file to allow for an alpha byte or would I have to adjust the brightness by replicating an "alpha change" through the use of the rgb bytes?

Any help with regards to this would be greatly appreciated.

Thanks


Solution

  • Get separate color component (6 bits ber component)

    #define RGBA_R(x)   (unsigned char)((x) & 0x0000003f)
    #define RGBA_G(x)   (unsigned char)(((x) >> 6) & 0x0000003f)
    #define RGBA_B(x)   (unsigned char)(((x) >> 12) & 0x0000003f)
    #define RGBA_A(x)   (unsigned char)(((x) >> 18) & 0x0000003f)
    

    form 24 bit color value

    #define COLOR24(r, g, b, a) (((r) & 0x3f) | (((g) & 0x3f) << 6) | (((b) & 0x3f) << 12) | (((a) & 0x3f) << 18))