Possible Duplicate:
How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?
Get Pixel color of UIImage
I have a scenario in which the user can select a color from an image, for example the one below:
Depending on the tap location of the user on the image I need to extract the RGB and alpha value at that very point—or say, pixel.
How do I accomplish this?
You need to create a bitmap context (
CGContextRef) from the image and convert theCGPointthat was tapped to an array offset location to retrieve the color information from the pixel data.See What Color is My Pixel? for a tutorial and this similar Stack Overflow question.
Methods:
Note that these methods are in a subclass of a
UIImageViewto make the process more straightforward.