wxImage to RGBA
Posted: Sat Feb 28, 2009 4:51 pm
wxImage::GetData return data in RGB format and wxImage::GetAlpha return alpha, please help - how to fast mix it to RGBA?
Official forum for the wxWidgets Cross-Platform GUI Toolkit
https://forums.wxwidgets.org/
Code: Select all
unsigned char *rgb = image.GetData();
unsigned char *alpha = image.GetAlpha();
unsigned char *result = (unsigned char *) malloc(image.GetWidth() * image.GetHeight() * 4);
for (unsigned int h = 0; h < image.GetHeight(); h++)
for (unsigned int w = 0; w < image.GetWidth(); w++)) {
*result++ = *rgb++; // copy red value
*result++ = *rgb++; // copy green value
*result++ = *rgb++; // copy blue value
*result++ = *alpha++; // copy alpha channel
}