iOS | 獲取到圖片的路徑后,將圖片保存到手機(jī)本地相冊中

1.先獲取到APP沙盒中的圖片路徑path
2.然后將path作為參數(shù),傳入下面的方法里,進(jìn)行圖片保存到手機(jī)本地相冊中。


#pragma mark 將截取到的頭像保存到本地相冊
- (void)saveHeaderImageWith:(NSString *)path
{
    UIImage *img = [UIImage imageWithContentsOfFile:path];
    [self saveImageToPhotos:img];
}

#pragma mark 保存圖片
- (void)saveImageToPhotos:(UIImage*)savedImage
{
    UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}

#pragma mark 系統(tǒng)的完成保存圖片的方法
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
    NSString *msg = nil ;
    if (error != NULL) {
        msg = @"保存圖片失敗" ;
    } else {
        msg = @"保存圖片成功" ;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存圖片結(jié)果提示" message:msg delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil];
    [alert show];
}




最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容