Color Sampling of Images

Discussion in 'iOS Programming' started by Shinji-23, Dec 18, 2008.

  1. Shinji-23 macrumors newbie

    Dec 18, 2008
    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:?
  2. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    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.

  3. Shinji-23 thread starter macrumors newbie

    Dec 18, 2008
    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?)

Share This Page