<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSImageRep/draw(in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSImageRep(im)drawInRect:"
  },
  "title" : "draw(in:)"
}
-->

# draw(in:)

Draws the image, scaling it (as needed) to fit the specified rectangle.

```
func draw(in rect: NSRect) -> Bool
```

## Parameters

`rect`

The rectangle in the current coordinate system in which to draw the image.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the image was successfully drawn; otherwise, <doc://com.apple.documentation/documentation/Swift/false>. If the size of the image has not yet been set, this method returns <doc://com.apple.documentation/documentation/Swift/false> immediately.

## Discussion

This method sets the origin of the current coordinate system to the origin of the specified rectangle before invoking the receiver’s [`draw()`](/documentation/AppKit/NSImageRep/draw()) method. If the rectangle size is different from the image’s native size, this method adjusts the coordinate transform, causing the image to be scaled appropriately.  After the `draw` method returns, the coordinate system changes are undone, restoring the original graphics state.

---

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)