1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| cocos2d::Image *image; int gap = 3; bool hasAlpha = image->hasAlpha(); if (hasAlpha) { gap = 4; } unsigned char *data = image->getData();
int width = image->getWidth(); int height = image->getHeight(); for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { unsigned char* pixel = data + (i + j * width) * gap; unsigned char r = *pixel; unsigned char g = *(pixel + 1); unsigned char b = *(pixel + 2) ; unsigned char a = hasAlpha ? *(pixel + 3) : 255; } }
|