我想获得UIImageView
中图像的颜色方案,例如RGB或CMYK。我怎么能这样做?
答案 0 :(得分:2)
在简单案例中,您可以通过访问UIImageView > .image > .CGImage > ColorSpace > Model
来访问颜色模型。
// briefly illustrating the common path, with no error checking:
UIImageView * imageView = ...;
UIImage * image = imageView.image;
CGImageRef cgImage = image.CGImage;
CGColorSpaceRef space = CGImageGetColorSpace(cgImage);
CGColorSpaceModel model = CGColorSpaceGetModel(space);
if (kCGColorSpaceModelRGB == model) {
...
}
else if (kCGColorSpaceModelCMYK == model) {
...
UIImageView
本身仅呈现/呈现图像。 UIImage
可以由不同的来源支持(例如CGImage
或CIImage
),并且它们可以代表许多不同的数据/图像类型。根据您的图像,您的实施可能需要支持其他案例。