<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Canvas/init(opaque:colorMode:rendersAsynchronously:renderer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6CanvasVA2A9EmptyViewVRszrlE6opaque9colorMode21rendersAsynchronously8rendererACyAEGSb_AA014ColorRenderingH0OSbyAA15GraphicsContextVz_So6CGSizeVtctcfc"
  },
  "title" : "init(opaque:colorMode:rendersAsynchronously:renderer:)"
}
-->

# init(opaque:colorMode:rendersAsynchronously:renderer:)

Creates and configures a canvas.

```
nonisolated init(opaque: Bool = false, colorMode: ColorRenderingMode = .nonLinear, rendersAsynchronously: Bool = false, renderer: @escaping (inout GraphicsContext, CGSize) -> Void)
```

## Parameters

`opaque`

A Boolean that indicates whether the canvas is fully
opaque. You might be able to improve performance by setting this
value to `true`, but then drawing a non-opaque image into the
context produces undefined results. The default is `false`.

`colorMode`

A working color space and storage format of the canvas.
The default is [`ColorRenderingMode.nonLinear`](/documentation/SwiftUI/ColorRenderingMode/nonLinear).

`rendersAsynchronously`

A Boolean that indicates whether the canvas
can present its contents to its parent view asynchronously. The
default is `false`.

`renderer`

A closure in which you conduct immediate mode drawing.
The closure takes two inputs: a context that you use to issue
drawing commands and a size — representing the current
size of the canvas — that you can use to customize the content.
The canvas calls the renderer any time it needs to redraw the
content.

## Discussion

Use this initializer to create a new canvas that you can draw into.
For example, you can draw a path:

```
Canvas { context, size in
    context.stroke(
        Path(ellipseIn: CGRect(origin: .zero, size: size)),
        with: .color(.green),
        lineWidth: 4)
}
.frame(width: 300, height: 200)
.border(Color.blue)
```

The example above draws the outline of an ellipse that exactly inscribes
a canvas with a blue border:

![A screenshot of a canvas view that shows the green outline of an](images/com.apple.SwiftUI/Canvas-1@2x.png)

For information about using a context to draw into a canvas, see
[`GraphicsContext`](/documentation/SwiftUI/GraphicsContext). If you want to provide SwiftUI views for the
renderer to use as drawing elements, use
[`init(opaque:colorMode:rendersAsynchronously:renderer:symbols:)`](/documentation/SwiftUI/Canvas/init(opaque:colorMode:rendersAsynchronously:renderer:symbols:))
instead.

---

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)