PDA

View Full Version : Color Sampling of Images




Shinji-23
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:?



firewood
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.


.

Shinji-23
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?)

PhoneyDeveloper
Dec 18, 2008, 03:37 PM
You might want to look at this method for hit testing

http://developer.apple.com/documentation/Carbon/Conceptual/QuickDrawToQuartz2D/tq_hit_test/chapter_9_section_3.html