wxImage to RGBA Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

wxImage to RGBA

Post by lester » 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?

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Sat Feb 28, 2009 5:04 pm

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
OS: Vista SP1, wxWidgets 2.8.7.

lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester » Sat Feb 28, 2009 5:20 pm

Big thanks for replay, Yes - that's simple and working solution, maybe I will cannot find faster

Post Reply