<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSBitmapImageRep/colorAt(x:y:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBitmapImageRep(im)colorAtX:y:"
  },
  "title" : "colorAt(x:y:)"
}
-->

# colorAt(x:y:)

Returns the color of the pixel at the specified coordinates.

```
func colorAt(x: Int, y: Int) -> NSColor?
```

## Parameters

`x`

The x-axis coordinate.

`y`

The y-axis coordinate.

## Return Value

A color object representing the color at the specified coordinates.

## Discussion

Calling this method creates a new [`NSColor`](/documentation/AppKit/NSColor) object. The overhead of object creation means this method is best suited for infrequent color sampling. If you instead need to work with large numbers of pixels, access the bitmap data directly using the [`bitmapData`](/documentation/AppKit/NSBitmapImageRep/bitmapData) property or the [`getPixel(_:atX:y:)`](/documentation/AppKit/NSBitmapImageRep/getPixel(_:atX:y:)) method for better performance.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)