Я написал метод для получения цвета из CGPoint в изображении:
ImageOperations.h:
+ (UIColor *)getColorFromImage:(UIImage*)image atX:(int)x andY:(int)y;
ImageOperations.m
+ (UIColor *)getColorFromImage:(UIImage*)image atX:(int)x andY:(int)y {
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = calloc(height * width * 4, sizeof(unsigned char));
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
int byteIdx = (bytesPerRow * y) + x * bytesPerPixel;
CGFloat red = (rawData[byteIdx] * 1.0) / 255.0;
CGFloat green = (rawData[byteIdx + 1] * 1.0) / 255.0;
CGFloat blue = (rawData[byteIdx + 2] * 1.0) / 255.0;
CGFloat alpha = (rawData[byteIdx + 3] * 1.0) / 255.0;
byteIdx += 4;
UIColor *acolor = [UIColor colorWithRed:red/255.f
green:green/255.f
blue:blue/255.f
alpha:alpha/255.f];
free(rawData);
return acolor;
}
Вызов метода выглядит так:
UIColor *myColor= [ImageOperations getColorFromImage:myImage atX:cgPoint.x andY:cgPoint.y];
self.myView.backgroundColor = myColor;
Надеюсь, это поможет.