Reputation: 115
I have an iPhone app where you can select a pixel from an image and it will return the RGBA colour details.
I need to be able to determine if the selected pixel is within a certain range of colour e.g. a light or dark variation of a specific colour.
What would be the most efficient way of doing this?
Upvotes: 1
Views: 129
Reputation: 6590
You will first have to convert your RGBA colorspace into HSBA (as suggested by @Zaph)
- (BOOL)getHue:(CGFloat *)hue saturation:(CGFloat *)saturation brightness:(CGFloat
*)brightness alpha:(CGFloat *)alpha
Once you know the hue, saturation and brightness, you could define a "3D sphere" around a specific point. Hue is what defines the color, saturation is how vivid your color is (or grayed), and brightness is the amount of luminosity.
I would assume that you want a tight hue, and a loose saturation and brightness values, no need to look at alpha if you do not have transparency.
Upvotes: 3