<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Image/init(size:label:opaque:colorMode:renderer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5ImageV4size5label6opaque9colorMode8rendererACSo6CGSizeV_AA4TextVSgSbAA014ColorRenderingH0OyAA15GraphicsContextVzctcfc"
  },
  "title" : "init(size:label:opaque:colorMode:renderer:)"
}
-->

# init(size:label:opaque:colorMode:renderer:)

Initializes an image of the given size, with contents provided by a
custom rendering closure.

```
init(size: CGSize, label: Text? = nil, opaque: Bool = false, colorMode: ColorRenderingMode = .nonLinear, renderer: @escaping (inout GraphicsContext) -> Void)
```

## Parameters

`size`

The size of the newly-created image.

`label`

The label associated with the image. SwiftUI uses the label
for accessibility.

`opaque`

A Boolean value that indicates whether the image is fully
opaque. This may improve performance when `true`. Don’t render
non-opaque pixels to an image declared as opaque. Defaults to `false`.

`colorMode`

The working color space and storage format of the image.
Defaults to [`ColorRenderingMode.nonLinear`](/documentation/SwiftUI/ColorRenderingMode/nonLinear).

`renderer`

A closure to draw the contents of the image. The closure
receives a [`GraphicsContext`](/documentation/SwiftUI/GraphicsContext) as its parameter.

## Discussion

Use this initializer to create an image by calling drawing commands on a
[`GraphicsContext`](/documentation/SwiftUI/GraphicsContext) provided to the `renderer` closure.

The following example shows a custom image created by passing a
`GraphicContext` to draw an ellipse and fill it with a gradient:

```
let mySize = CGSize(width: 300, height: 200)
let image = Image(size: mySize) { context in
    context.fill(
        Path(
            ellipseIn: CGRect(origin: .zero, size: mySize)),
            with: .linearGradient(
                Gradient(colors: [.yellow, .orange]),
                startPoint: .zero,
                endPoint: CGPoint(x: mySize.width, y:mySize.height))
    )
}
```

![An ellipse with a gradient that blends from yellow at the upper-](images/com.apple.SwiftUI/Image-2@2x.png)

---

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)