//cocos2dx获取图片某一点的颜色Color4B getColor(float posx,float posy){ Image * _colorImage = new Image(); _colorImage-initWithImageFile("original/yi001.png"); unsigned char *m_pData = _colorImage-getData(); int x =(int)posx; int y
//cocos2dx获取图片某一点的颜色
Color4B getColor(float posx,float posy)
{
Image * _colorImage = new Image();
_colorImage->initWithImageFile("original/yi001.png");
unsigned char *m_pData = _colorImage->getData();
int x =(int)posx;
int y =(int)posy;
Color4B c = { 0, 0, 0, 0 };
//转换GL坐标
int ix = x - 1;
int iy = _colorImage->getHeight()-y + 1;
m_pData += (iy*_colorImage->getWidth() + ix) * 4;
c.r = *(m_pData++);
c.g = *(m_pData++);
c.b = *(m_pData++);
c.a = *(m_pData++);
CCLOG("color r:%d g:%d b:%d a:%d ", c.r, c.g,c.b,c.a)
return c;
}
