How to get the pixel color values of custom image inside imageview ios?

前端 未结 4 1254
失恋的感觉
失恋的感觉 2021-01-03 05:59

I know similar question have been asked before.

What I want is to get the RGB pixel value of the Image Inside the Imageview, so it can be any image that

4条回答
  •  死守一世寂寞
    2021-01-03 06:18

    If you try to get color from image through CGBitmapContextGetData and set, for example, in background of view, this will be different colors in iPhone 6 and later. In iPhone 5 everything will be ok) More information about this Getting the right colors in your iOS app

    This solution through UIImage give you right color:

    - (UIColor *)getColorFromImage:(UIImage *)image pixelPoint:(CGPoint)pixelPoint {
    
        CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(pixelPoint.x, pixelPoint.y, 1.f, 1.f));
        UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
    
        return [UIColor colorWithPatternImage:croppedImage];
    
    }
    

提交回复
热议问题