参考サイト
Objective-Cと戦うブログ: UIImageをフォトライブラリに保存する
iPhone:画像をライブラリに保存するメソッドUIImageWriteToSavedPhotosAlbumの注意事項 | mthr Blog+
UIImageをカメラロールに保存(iOS, Objective-C) – nktmemo
コードとしては
UIImageWriteToSavedPhotosAlbum(イメージ, self, @selector(完了時に呼ばれるメソッド), nil);
って感じ。
カメラロールに保存される場合はファイル名を指定できないぽい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
//画像を保存する -(void)saveImage { //保存したい画像 UIImage *_saveImage = [UIImage imageNamed:@"image.png"]; UIImageWriteToSavedPhotosAlbum(_saveImage, self, @selector(savingImageIsFinished:didFinishSavingWithError:contextInfo:), nil); } // 完了を知らせる - (void) savingImageIsFinished:(UIImage *)_image didFinishSavingWithError:(NSError *)_error contextInfo:(void *)_contextInfo { if(_error){//エラーのとき // コントローラを生成 UIAlertController * ac = [UIAlertController alertControllerWithTitle:@"Error" message:@"Save failed ." preferredStyle:UIAlertControllerStyleAlert]; // OK用のアクションを生成 UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { // ボタンタップ時の処理 NSLog(@"OK button tapped."); }]; // コントローラにアクションを追加 [ac addAction:okAction]; // アラート表示処理 [self presentViewController:ac animated:YES completion:nil]; }else{//保存できたとき return; } } |