Why the screenshot is blurred even though the .captureResolution is set to .best and configuration.width is set to 3840 * 2.
It outputs the image in the size set with the configuration.width, but still blurred regardless of the high resolution image it produces.
I'm trying to capture as image (screenshot), not as video.
I don't expect the quality more than my current display, however, the output is worse than the current display. When I take a screenshot with macOS standard screenshot tool, then the quality is perfect. Seems only the screenshot manager is not working properly.
Errors: No errors
@objc func takeScreenshot() {
Task {
do {
let content = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: false)
guard let mainDisplayID = NSScreen.main?.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID,
let display = content.displays.first(where: { $0.displayID == mainDisplayID }) else { return }
let configuration = SCStreamConfiguration()
configuration.captureResolution = .best
configuration.sourceRect = CGRect(x: 400, y: 400, width: 800, height: 800)
configuration.width = 3840 * 2
configuration.height = 2160 * 2
configuration.pixelFormat = kCVPixelFormatType_32BGRA
configuration.preservesAspectRatio = true
configuration.capturesAudio = false
configuration.scalesToFit = false
let filter = SCContentFilter(display: display, excludingWindows: [])
let capturedImage = try await SCScreenshotManager.captureImage(contentFilter: filter, configuration: configuration)
let nsImage = NSImage(cgImage: capturedImage, size: NSZeroSize)
self.imageView.image = nsImage
} catch {
print("Error capturing screen: \(error)")
}
}
}
Same problem here.
I found that it will become blurred if
sourceRectis set.So I replace
sourceRectwith image cropping.