Snapshot is super blurry . . . similar approach in UIKit works just fine

UIGraphicsBeginImageContextWithOptions(controller.view.bounds.size, true, 0.0) doesn’t help in this case

private var tile: some View {
  .....
}

var body: some View {
  GeometryReader { proxy in
    VStack(alignment: .center, spacing: ShareViewConstants.primarySpacing) {
      self.tile.frame(maxHeight: proxy.size.height * xxx)
        ....
    }
  }
  .onTapGesture {
    UIImageWriteToSavedPhotosAlbum(tile.snapshot(), nil, nil, nil)
    self.isPresented = true
  }
}

extension View {
  func snapshot() -> UIImage {
    let controller = UIHostingController(rootView: self)
    let view = controller.view
    
    let targetSize = controller.view.intrinsicContentSize
    view?.bounds = CGRect(origin: .zero, size: targetSize)
    view?.backgroundColor = .clear
    
    let renderer = UIGraphicsImageRenderer(size: targetSize)
    
    return renderer.image { _ in
      view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)
    }
  }
}

Oh so sorry but i am not sure about that… Thanks !!

Code error . . .

This topic was automatically closed after 166 days. New replies are no longer allowed.