以下代码将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);
...
此代码在为iPhone编译时失败,因为iPhone版本的Core Graphics不包含CGImageDestinationRef
。有没有办法使用原生iPhone框架和库将CFImageRef
保存到jpeg?我能想到的唯一选择是放弃Core Graphics并使用ImageMagick。
答案 0 :(得分:9)
UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f);
[jpgData writeToFile:...