I use CCImage to load a png file and test the CCImage->getData(), it works ok on my computer. Could you please discribe it more specificly? Like what kind of image file you loaded, where and how you use it. Thank you!
I need to get the raw data from my png file. I attached the file here. It is a coloring app. I need the raw data to modify the bytes of the image.
static UInt8 pixdata;
static UInt32 pixsize;
CCImageimg = new CCImage();
img~~>initWithImageFile;
int alp = 3;
if) {
CCLOG (“has Alpha”);
alp = 4;
}
pixsize = alp * img~~>getDataLen();
pixdata = new unsigned char[pixsize];
pixdata = img->getData(); //HERE IS THE PROBLEM on android. It works ok on iOS
Any progress with this? I am having almost the same problem, on Android. In my case, the app does not crash, but the pixel data is not complete. I think the function CCImage::getDataLen() is returning the wrong value too.
For example, my image is 50x50 pixels. If I call getDataLen() on the image after loading it returns 2500 which is incorrect - it should be 10000 (because RGBA8888 should be 4 * 50 * 50).
I can access the pixel data, but only up to the position given by getDataLen(), and it seems like the data only contains every 4th pixel.
Okay, I have seen from other posts here that the getDataLen() function just returns the number of pixels!
But we can already get the number of pixels using getWidth() and getHeight().
The term ‘data length’ usually means a number bytes, and even the CCImage header uses it like that everywhere else. Very confusing.
Also, when you have a function called getData(), then a companion function called getDataLen() should return the length of that data (bytes!), not some other length.