2010-03-03 46 views
2

以下代码将PDF页转换为JPEG。它按预期运行在Snow Leopard上:编译时的iPhone,因为核芯显卡的iPhone版本不包括CGImageDestinationRef是否可以在iPhone上使用Core Graphics保存图像?

... 
//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框架和库将CFImageRef保存为jpeg吗?我能想到的唯一选择是放弃Core Graphics并使用ImageMagick。

回答

9
UIImage *myImage = [UIImage imageWithCGImage:image]; 
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f); 
[jpgData writeToFile:... 
相关问题