View Full Version : Color Sampling of Images
Dec 18, 2008, 02:06 PM
I was planning on using a non-displayed image for hit detection by getting the color of the image at the point corresponding to the touch. I can't seem to find anyway to do this in the iPhone SDK.
Does anybody know of an equivalent of NSBitmapImageRep's colorAtX:y:?
Dec 18, 2008, 02:51 PM
If you have a pointer to the raw bitmap, and know the bytes-per-row and bytes-per-pixel, then it's a couple multiplies and an add to get a pointer to the raw pixel data from an X,Y coordinate.
Dec 18, 2008, 03:13 PM
If you have a pointer to the raw bitmap...
How do you get at that? Would that be CGImageGetDataProvider(image.CGImage)? Even if it is, do I have to realize that it's a PNG backing and code up the PNG reading standard to get at my color?
(And if it is, how do I get data out of the CGDataProviderRef?)
Dec 18, 2008, 03:37 PM
You might want to look at this method for hit testing