This code used to work, however I think Xcode s new ARC may have killed it
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
CGDirectDisplayID displayID = CGMainDisplayID();
CGImageRef image = CGDisplayCreateImage(displayID); //this is a screenshot (works fine)
[self savePNGImage:image path:@"~/Desktop"];
}
-(void)savePNGImage:(CGImageRef)imageRef path:(NSString *)path {
NSURL *outURL = [[NSURL alloc] initFileURLWithPath:path];
//here xcode suggests using __bridge for CFURLRef?
CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((__bridge CFURLRef)outURL, (CFStringRef)@"public.png" , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, NULL);
CGImageDestinationFinalize(dr);
}
该法典将错误归为:
ImageIO: CGImageDestinationAddImage image destination parameter is nil
我假设的是,CGImageDestinationRef不是正在正确创建的。 我没有能够发现这一点,即新的X条码并没有给我留下同样的错误,而我是错了吗?