Alex Corbi CCImage getData() RGBA infos , Android
Posts 1
Added by Alex Corbi 11 months ago

Hi Community,

I am porting a game i did for iOS using cocos2d-iphone to Android.

I need to extract the RGBA ( alpha channel inclusive ) pixel information from an Image stored in the Resources folder, i use the following code:

// Extract pixel information from Image
CCImage image = new CCImage();
image->initWithImageFile(spriteName);
unsigned char*layerPixels = image->getData();
int length = strlen((char
)layerPixels);

The problem is that the length of the layerPixels variable is width*height*3 , meaning RGB information, but i also need the alpha channel information.

Do you know how to do it? i am using cocos2d-1.0.1-x-0.13.0-beta

Thanks in advance.

James Chen RE: CCImage getData() RGBA infos , Android
Posts 671
Added by James Chen 11 months ago

Is it a jpeg image? If so, you need to make up alpha channel manually.
You can use CCImage::hasAlpha method to find out whether the image has an alpha channel.


(1-1/1)