是否可以在iPhone上使用Core Graphics保存图像?

Ben*_*hen 2 iphone core-graphics quartz-2d

以下代码将PDF页面转换为JPEG.它在Snow Leopard上按预期运行:

...
//get the image from the bitmap context
CGImageRef image = CGBitmapContextCreateImage(outContext);

//create the output destination
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, kUTTypeJPEG, 1, NULL);

//add the image to the output file
CGImageDestinationAddImage(outfile, image, NULL);
CGImageDestinationFinalize(outfile);
...
Run Code Online (Sandbox Code Playgroud)

编译为iPhone时此代码失败,因为iPhone版本的Core Graphics不包括CGImageDestinationRef.有没有办法CFImageRef使用本机iPhone框架和库保存到jpeg?我能想到的唯一选择是放弃Core Graphics并使用ImageMagick.

Ole*_*ann 9

UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f);
[jpgData writeToFile:...
Run Code Online (Sandbox Code Playgroud)