智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...

导航

cocos2d-x 获取图片的某像素点的RGBA颜色

Posted on 2013-07-10 14:17  Bill Yuan  阅读(1386)  评论(0编辑  收藏  举报

转自:http://www.cnblogs.com/jaoye/archive/2013/02/19/2916501.html

ccColor4B c = {0, 0, 0, 0};
CCPoint pt = ccp(240,160);//要获取的点
unsigned int x = pt.x, y = pt.y;
 
CCImage * myimg = new CCImage();
//加载 图片
myimg->initWithImageFileThreadSafe("HelloWorld1.png");
unsigned char *data_=myimg->getData();
unsigned int *pixel = (unsigned int *)data_;
pixel = pixel + (y * 480) + x;        //480 是图片的宽
c.r = *pixel & 0xff;
c.g = (*pixel >> 8) & 0xff;
c.b = (*pixel >> 16) & 0xff;
c.a = (*pixel >> 24) & 0xff;          //这个值  就是透明度