我怎样才能获得UIImage的配色方案?

时间:2013-12-03 09:21:49

标签: ios objective-c uiimageview uiimage

我想获得UIImageView中图像的颜色方案,例如RGB或CMYK。我怎么能这样做?

1 个答案:

答案 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可以由不同的来源支持(例如CGImageCIImage),并且它们可以代表许多不同的数据/图像类型。根据您的图像,您的实施可能需要支持其他案例。

相关问题