Color Sampling of Images

Discussion in 'iPhone/iPad Programming' started by Shinji-23, Dec 18, 2008.

  1. macrumors newbie

    Joined:
    Dec 18, 2008
    #1
    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. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    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. thread starter macrumors newbie

    Joined:
    Dec 18, 2008
    #3
    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?)
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4

Share This Page