#pragma mark 先獲取本地圖片或者網絡圖片 - (void)saveHeaderImageWith:(NSString *)path { UIImage *img = [UIImage imageWithContentsOfFile:path]; //這里img也可以是從網絡獲取的圖片 [self saveImageToPhotos:img]; } #pragma mark 保存圖片 - (void)saveImageToPhotos:(UIImage*)savedImage { UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); } #pragma mark 系統的完成保存圖片的方法 - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo { NSString *msg = nil ; if (error != NULL) { msg = @"保存圖片失敗" ; } else { msg = @"保存圖片成功" ; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存圖片結果提示" message:msg delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alert show]; }
