Screenshot with ScreenCaptureKit much larger than with Command-Shift-3

I am capturing a screenshot with SCScreenshotManager's captureImageWithFilter. The resulting PNG has the same resolution as the PNG taken from Command-Shift-3 (4112x2658) but is 10x larger (14.4MB vs 1.35MB).

My SCStreamConfiguration uses the SCDisplay's width and height and sets the color space to kCGColorSpaceSRGB.

I currently save to file by initializing a NSBitmapImageRep using initWithCGImage, then representing as PNG with representationUsingType NSBitmapImageFileTypePNG, then writeToFile:atomically.

Is there some configuration or compression I can use to bring down the PNG size to be more closely in-line with a Command-Shift-3 screenshot.

Thanks!

Hello @lienetic,

Certainly this has something to do with the way you are writing the PNG.

Try using Image I/O for writing, I suspect you will get a more reasonable file size:

let destination = CGImageDestinationCreateWithURL(outputURL as CFURL, UTType.png.identifier as CFString, 1, nil)!
                            
CGImageDestinationAddImage(destination, image, nil)
                            
CGImageDestinationFinalize(destination)

// open the file in Preview to examine its size.                            
NSWorkspace.shared.open(outputURL)
Screenshot with ScreenCaptureKit much larger than with Command-Shift-3
 
 
Q