Getting image's pixel RGBA

I’m sorry for asking this here, but i’m like browsing whole day for this…
How to get an image’s single pixel RGBA and copy it into an array?
And it’s not the whole screen, like using glreadpixel

my friend in cocos2d iphone use this code to do it…
the CGDataProviderCopyData thing, only do exist in xcode he says…

-(unsigned char**)makeDressMap {
NSString**tempString = [NSString stringWithFormat:`“dress%i.png”,dressID];
UIImage *tempDressImage = [UIImage imageNamed:tempString];

int width = (int)tempDressImage.size.width;
int height = (int)tempDressImage.size.height;

CCLOG(`“w i",width);
CCLOG(@"h i”,height);
>
unsigned char collisionMap = malloc;
memset;
>
CFDataRef imageData = CGDataProviderCopyData);
const UInt32
pixels = (const UInt32*)CFDataGetBytePtr(imageData);
>
for (int j = 0; j<(width*height); j++) {
if (pixels[j] & 0xff000000) {
collisionMap[j] |= 1;
//CCLOG(@“%i”,collisionMap[j]);
}
}
>
CFRelease(imageData);
return collisionMap;
}

I’m not sure of a simple “get one pixel” call but you can get access to an images data using “CCImage->getData();”

Have a look at the file CCTexture2D.cpp, function:
bool CCTexture2D::initPremultipliedATextureWithImage(CCImage *image, unsigned int POTWide, unsigned int POTHigh)

it uses a CCImage and calls “tempData = (unsigned char*)(image->getData());”.

Appreciate for answering, and I have read it a little…
I think it has something loop for whole image…
But my boss said it doesn’t need to be exactly in the image, so this case will be closed for a while :slight_smile: