Reputation: 3663
I want to change the color where user touch on image. I got some code to get the image data which is below
NSString * path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"jpg"];
UIImage * img = [[UIImage alloc]initWithContentsOfFile:path];
CGImageRef image = [img CGImage];
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(image));
const unsigned char * buffer = CFDataGetBytePtr(data);
I know I can easily get the touch point but my questions are below
Upvotes: 1
Views: 785
Reputation: 62676
Add a gesture recognizer to the UIImageView that presents the image. When that recognizer is triggered, the location you care about will be...
// self.imageView is where you attached the recognizer. This == gestureRecognizer.view
CGPoint imageLocation = [gestureRecognizer locationInView:self.imageView];
Resolving this location to a pixel location device independently can be done by determining the scale factor of the image.
To get the image location, apply that scale factor to the gesture location...
CGPoint pixel = CGPointMake(imageLocation.x*image.scale, imageLocation.y*image.scale)
This should be the correct coordinate for accessing the image. The remaining step is to get the pixel data. This post provides a reasonable-looking way to do that. (Also haven't tried this personally).
Upvotes: 1