干货:
Image* img = new Image();
img->initWithImageFile("....png");
Color4B getColor4B(float x,float y)
{
Color4B color = { 0,0, 0,0 };
if(x<0.f || y<0.f || x>img->getWidth() || y>img->getHeight())
{
CCLOG(" x or y is not in range of the image. W:%d, H:%d",
x, y, img->getWidth(), img->getHeight());
return color; //越界可做其他处理
}
int ix = (int)x -1;
int iy = (int)y -1;
unsignedchar* pos = m_pData;
pos += (iy*img->getWidth() + ix) * 4;
color.r = *(pos++);
color.g = *(pos++);
color.b = *(pos++);
color.a = *(pos++);
return color;
};
用完了记得 : CC_SAFE_DELETE (img);