Determining the Colorspace of a UIImage

吃可爱长大的小学妹 提交于 2019-12-23 15:50:23

问题


I'm wondering if there's an easy way to get the colorspace of an image (i.e. an image loaded into a UIImage)? For example, I have a TIFF image and I'd like to be able to determine if it uses the RGB colorspace or not. Is there an easy way to do this without manipulating pixel data? I know there's some CGColorSpace functions, but none of them seem to do this, just create colorspaces and manipulate them (and much more advanced functions).

Thanks in advance.


回答1:


You have to get the color space through CGImage. You can do it with the following line of functions/properties:

@property(nonatomic, readonly) CGImageRef CGImage

CGColorSpaceRef CGImageGetColorSpace (
   CGImageRef image
);

So to get the color space of an image, you'd do:

CGColorSpaceRef colorspace = CGImageGetColorSpace([myUIImage CGImage]);

And of course, make sure to follow the get/create/copy rules for CG objects.



来源:https://stackoverflow.com/questions/4168972/determining-the-colorspace-of-a-uiimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!