<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.6.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCachedImageRep/initWithSize:depth:separate:alpha:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCachedImageRep(im)initWithSize:depth:separate:alpha:"
  },
  "title" : "initWithSize:depth:separate:alpha:"
}
-->

# initWithSize:depth:separate:alpha:

Returns a cached image representation initialized with the specified image characteristics.

```
- (id) initWithSize:(NSSize) size depth:(NSWindowDepth) depth separate:(BOOL) flag alpha:(BOOL) alpha;
```

## Parameters

`size`

The size of the image, measured in points.

`depth`

The bit depth of the image. Specify 0 if you want the image to be the same depth as the deepest screen on the current system.

`flag`

<doc://com.apple.documentation/documentation/Swift/true> if the receiver should use a separate offscreen window to store the image; otherwise, <doc://com.apple.documentation/documentation/Swift/false> if the receiver should use a shared window.

`alpha`

<doc://com.apple.documentation/documentation/Swift/true> if the image includes transparency information; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Return Value

The initialized `NSCachedImageRep` object or `nil` if the object could not be initialized.

## See Also

[`- (void) setCacheDepthMatchesImageDepth:(BOOL) flag;`](/documentation/AppKit/NSImage/setCacheDepthMatchesImageDepth:)

Sets whether the image’s offscreen window caches use the same bit depth as the image data itself.

[`var hasAlpha: Bool`](/documentation/AppKit/NSImageRep/hasAlpha)

A Boolean value that indicates whether the image data has an alpha channel.

[`- (void) setCachedSeparately:(BOOL) flag;`](/documentation/AppKit/NSImage/setCachedSeparately:)

Sets whether each image representation uses a separate offscreen window to cache its contents.

[`var bitsPerSample: Int`](/documentation/AppKit/NSImageRep/bitsPerSample)

The number of bits per sample in the object (if the object is a planar image, this property contains the number of bits per sample per plane).



---

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)