For example, I have a UIImage, I would like to know the image position (300, 200) is which color, how can I do so? Thanks.
Asked
Active
Viewed 1,353 times
1
-
2Check this - http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or-cgimage-core-graphics – rishi Nov 08 '12 at 06:35
-
you should try the technique matt describes here: http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiimage -- of course, using a color destination bitmap. the benefit is that you don't need to allocate and draw the whole image to access the value of one pixel. – justin Nov 08 '12 at 06:42
1 Answers
4
Call this method form uitouch move..
-(void) getPixelColorAtLocation:(CGPoint)point
{
unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.layer renderInContext:context];
// NSLog(@"x- %f y- %f",point.x,point.y);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
NSLog(@RGB Color code "%d %d %d",pixel[0],pixel[1],pixel[2]);
}
You can get color code of touch point in RGB colr combination. try it