例如,我有一个UIImage,我想知道图像位置(300,200)是哪种颜色,我该怎么办?谢谢。
答案 0 :(得分:3)
从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]);
}
您可以在RGB颜色组合中获得触摸点的颜色代码。 试试吧