Code:
//Load in the image we want to analyse
UIImage *c = [UIImage imageNamed:@"test.jpg"];
//Convert image to format we can look at
CGImageRef inImage = CGImageRetain(c.CGImage);
CGContextRef ctx;
//Get the pixel data from the image
CFDataRef m_DataRef;
m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
// Byte tmpByte;
int length = CFDataGetLength(m_DataRef);
//NSLog(@"len %d", length);
int bytesPerPixel = 4;
int imageWidth = CGImageGetWidth(inImage);
int imageHeight = CGImageGetHeight(inImage);
int x = 25;
int y = 25;
int offset = 4*((imageWidth*round(Y))+round(X))
NSLog(@"offset:%i", offset);
m_PixelBuf[offset+1] = 255;
m_PixelBuf[offset+2] = 1;
m_PixelBuf[offset+3] = 1;
//Create an image from the pixel data
ctx = CGBitmapContextCreate(m_PixelBuf,
CGImageGetWidth( inImage ),
CGImageGetHeight( inImage ),
8,
CGImageGetBytesPerRow( inImage ),
CGImageGetColorSpace( inImage ),
kCGImageAlphaPremultipliedFirst );
CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
UIImage* rawImage = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
//Set the UIImage to the new image data
testPic2.image = rawImage;
thats a rough outline of the code im using, picture im testing on is a 50px by 50px pixel just as a test yet trying to get x,y of 25,25 doesn't yield the pixel in the dead center of the image