本文介绍了使用UIImageWriteToSavedPhotosAlbum保存图像,但是内存已满,如何捕获错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码:
UIImageWriteToSavedPhotosAlbum(_curView.image, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);
将图像保存到相册.每当我的设备的内存已满时,我就会使用此选择器:
to save the images to the album. Whenever my device's memory is full, I am using this selector:
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
,但它不能识别错误,实际上,error
为nil.发生错误时,我的设备内存已满.
but it didn't identify the error, in fact, error
is nil.When the error occurs my device's memory is full.
如何检测内存是否可用?
How can I detect if the memory is available or not?
推荐答案
我遇到了同样的问题.看来您无法直接从UIImageView
保存图像.您需要拍摄快照并保存它. Swift 3示例:
I got the same issue. It seems that you cannot save the image directly from your UIImageView
. You need to take a snapshot and save it instead. Swift 3 example:
func takeSnapshot() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, UIScreen.main.scale);
imageView.drawHierarchy(in: imageView.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这篇关于使用UIImageWriteToSavedPhotosAlbum保存图像,但是内存已满,如何捕获错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!