Page 1 of 1

wxImage to RGBA

Posted: Sat Feb 28, 2009 4:51 pm
by lester
wxImage::GetData return data in RGB format and wxImage::GetAlpha return alpha, please help - how to fast mix it to RGBA?

Posted: Sat Feb 28, 2009 5:04 pm
by JimFairway
Hi,

Do you mean you want to create an array of RGBA? If so,

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
}
Hope that's what you were looking for...

Jim

Posted: Sat Feb 28, 2009 5:20 pm
by lester
Big thanks for replay, Yes - that's simple and working solution, maybe I will cannot find faster