Skip to content

Taking View capture with cacheDisplay is buggy #6

@auramagi

Description

@auramagi

These are current view capture steps:

  1. Add template View to NSHostingController
  2. Add it to a custom NSWindow
  3. Save as image with cacheDisplay(in:to:)

However, using cacheDisplay produces some side-effects and the resulting image does not exactly match View as displayed.

To get around some display issues, we tell SwiftUI to first flatten view hierarchy by itself using the drawingGroup modifier.

But even this has some weirdness, especially with blend modes. First of all, it loses all transparency, but that part is at least consistent with previews/actual rendering after using drawingGroup.

Using .overlay(Color.mint.blendMode(.hue)):

We can get around that by masking the result with the initial view:

@ViewBuilder public func hue(_ color: Color) -> some View {

But this still leaves us with incorrectly blended color in some parts.

Compare to how this looks in previews and when displayed in a window.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions