且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS image内容保存到本地相册

更新时间:2022-08-23 10:05:21

如下代码所示

点击按钮,将self.imageView上面的image内容保存到本地相册,并指定判断保存成功与否的方法imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:

- (IBAction)saveImageToAlbum:(id)sender {
    
UIImageWriteToSavedPhotosAlbum(self.imageView.imageself@selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}

实现imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:方法

- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    
NSString *message = @"成功";
    
if (!error) {
        message = 
@"成功保存到相册";
    }
else
    {
        message = [error 
description];
    }
    
NSLog(@"message is %@",message);
}

这些代码很简单,如果没有错误的话就提示“成功保存到相册”,如果保存失败的话,那么就输出错误信息[error description]。











本文转自 卓行天下  51CTO博客,原文链接:http://blog.51cto.com/9951038/1842721,如需转载请自行联系原作者