开发者

Is it possible to save an image with Core Graphics on the iPhone?

开发者 https://www.devze.com 2022-12-21 16:00 出处:网络
The following code converts a PDF page into a JPEG. It runs as expected on Snow Leopard: ... //get the image from the bitmap context

The following code converts a PDF page into a JPEG. It runs as expected on Snow Leopard:

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

//crea开发者_运维问答te the output destination
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, kUTTypeJPEG, 1, NULL);

//add the image to the output file
CGImageDestinationAddImage(outfile, image, NULL);
CGImageDestinationFinalize(outfile);
...

This code fails when compiled for iPhone because the iPhone version of Core Graphics does not include CGImageDestinationRef. Is there any way to save CFImageRef to a jpeg using the native iPhone frameworks and libraries? The only alternative I can think of is to ditch Core Graphics and use ImageMagick.


UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f);
[jpgData writeToFile:...
0

精彩评论

暂无评论...
验证码 换一张
取 消