Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taking View capture with cacheDisplay is buggy #6

Open
auramagi opened this issue Jun 3, 2022 · 2 comments
Open

Taking View capture with cacheDisplay is buggy #6

auramagi opened this issue Jun 3, 2022 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@auramagi
Copy link
Owner

auramagi commented Jun 3, 2022

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.

@auramagi auramagi added the help wanted Extra attention is needed label Jun 3, 2022
@auramagi
Copy link
Owner Author

auramagi commented Jun 6, 2022

iOS 16 / macOS Ventura brings the new ImageRenderer class 🎉

Need to test whether it solves these problems.

@auramagi
Copy link
Owner Author

auramagi commented Jun 7, 2022

ImageRenderer does seem to eliminate blend mode problems, but so does cacheDisplay in Ventura 🤔

cacheDisplay ImageRenderer

ImageRenderer output seems to be blurry, but maybe I'm just holding it wrong. Will revisit later, for now experimental support is in feature/ImageRenderer branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant