使用UIImageWriteToSavedPhotosAlbum控制图像质量 [英] Control image quality with UIImageWriteToSavedPhotosAlbum

查看:315
本文介绍了使用UIImageWriteToSavedPhotosAlbum控制图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将当前屏幕保存到照片库:

I'm using code like the following to save the current screen to the photos library:

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();     
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(result, nil,nil, nil);

这样可行,但质量看起来很像压缩的JPG(保存的文件名是标准IMG_XXXX.JPG格式),即使此代码中没有指定的图像类型或其质量。有没有办法控制质量?即我可以将它保存为未压缩的PNG吗?

This works, but the quality looks a lot like a compressed JPG (and the file name saved is in the standard IMG_XXXX.JPG format), even though nowhere in this code is the type of image or its quality specified. Is there a way to control quality? I.e. could I have it saved as an uncompressed PNG instead?

推荐答案

您可以使用<$ c $将其保存为PNG c> UIImagePNGRepresentation() NSData 的方法,执行以下操作:

You can save it as a PNG by utilizing the UIImagePNGRepresentation() method for NSData, do something like this:

....
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData* data =  UIImagePNGRepresentation ( result );
UIImage* pngImage = [UIImage imageWithData:data];
UIImageWriteToSavedPhotosAlbum(pngImage, nil, nil, nil);

希望这会有所帮助。

这篇关于使用UIImageWriteToSavedPhotosAlbum控制图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆