2

以下代码将 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. 有没有办法CFImageRef使用原生 iPhone 框架和库保存到 jpeg?我能想到的唯一选择是放弃 Core Graphics 并使用 ImageMagick。

4

1 回答 1

9
UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f);
[jpgData writeToFile:...
于 2010-03-03T11:45:37.103 回答