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

- (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;
}

你可能感兴趣的:(获取一个图片像素点RGB值的代码)