Search code examples
objective-ccocoansimage

How to check the color of a certain part of an image?


I am making a simple game that uses "AI players" (they aren't really AI players). I need to find out if a certain part of the "map" I am using has certain colors, so I can make the "AI players" do certain things. Is it possible to do this?

I don't know if this will help, but a game called "Warcraft 3" uses a very similar thing to determine certain things, such as movement. If you know of this game, it should be a lot easier to understand this question.

I think this may be possible if I put the image into a custom NSView subclass, but I have not yet learned how to check colors there either.


Solution

  • Create a NSBitmapImageRep from the NSImage and use colorAtX:y: to get the color.

    Check:
    NSBitmapImageRep Class Reference