如何从CGImage获取Raw像素数据

如何从CGImage获取Raw像素数据

问题描述:

如何在缩放和移动后获取UIimage的像素数据,我想获取CGImage Pixel Data,然后从CGImage Pixel Data获取UIImage。我们可以这样做吗?

How to get the Pixel Data of UIimage after scaling and moving,I wan to get the CGImage Pixel Data and then get the UIImage from CGImage Pixel Data.How can we do this?.

你可以通过调用来获取rawdata

You can get the rawdata by calling

CFDataRef rawData = CGDataProviderCopyData(CGImageGetDataProvider(aCGImageRef));

您可以单步执行以下像素:

You can step through pixels like this:

UInt8 * buf = (UInt8 *) CFDataGetBytePtr(rawData); 
CFIndex length = CFDataGetLength(rawData);

for(unsigned long i=0; i<length; i+=4)
{
    int r = buf[i];
    int g = buf[i+1];
    int b = buf[i+2];
     }
CFRelease(rawData);