Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Raw pixel data from CGImage [duplicate]

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?.

like image 791
user1362790 Avatar asked May 02 '12 10:05

user1362790


1 Answers

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);
like image 189
Jonas Schnelli Avatar answered Oct 07 '22 16:10

Jonas Schnelli