获取一个图片像素点RGB值的代码

以下是由CocoaChina会员 “上帝的大大” 分享的代码,用于获取图片信息,查询像素点的RGB值。 帖子地址 http://www.cocoachina.com/bbs/read.php?tid-13152.html

 

- (void*)getImageData:(UIImage*)image
{
    void* imageData;
    if (imageData == NULL) 
        imageData = malloc(4 * image.size.width * image.size.height);
    
    CGColorSpaceRef cref = CGColorSpaceCreateDeviceRGB();
    CGContextRef gc = CGBitmapContextCreate(imageData,
                                            image.size.width,image.size.height,
                                            8,image.size.width*4,
                                            cref,kCGImageAlphaPremultipliedFirst);
    CGColorSpaceRelease(cref);
    UIGraphicsPushContext(gc);
    
    [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
    
    UIGraphicsPopContext();
    CGContextRelease(gc);
    
    return imageData;
}

你可能感兴趣的:(cocos2dx)