10 MetalScreenshot::MetalScreenshot(CGImageRef cgImage) : cg_image_(cgImage) {
11 CGDataProviderRef data_provider = CGImageGetDataProvider(cgImage);
12 pixel_data_ = CGDataProviderCopyData(data_provider);
16 CFRelease(pixel_data_);
17 CGImageRelease(cg_image_);
21 return CFDataGetBytePtr(pixel_data_);
25 return CGImageGetHeight(cg_image_);
29 return CGImageGetWidth(cg_image_);
35 [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]];
36 CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
37 (__bridge CFURLRef)output_url, kUTTypePNG, 1,
nullptr);
38 if (destination !=
nullptr) {
39 CGImageDestinationAddImage(destination, cg_image_,
40 (__bridge CFDictionaryRef) @{});
42 if (CGImageDestinationFinalize(destination)) {
46 CFRelease(destination);