次の疑問があります。
写真(画像)を「特定の名前」で写真アルバムに保存できますか、または保存後に写真の名前にアクセスできますか?
フォト アルバムからその名前で写真にアクセスできますか?
助けてください。
前もって感謝します。
次の疑問があります。
写真(画像)を「特定の名前」で写真アルバムに保存できますか、または保存後に写真の名前にアクセスできますか?
フォト アルバムからその名前で写真にアクセスできますか?
助けてください。
前もって感謝します。
これは、ユーザー指定の名前で画像を書き込むためのコードです
// Create paths to output images
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
// Let's check to see if files were successfully written...
// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
UIImagePickerControllerDelegate
カメラまたは画像ライブラリを呼び出すためのデリゲートの使用。
カメラを呼び出すには:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
isCamera = YES;
[self presentModalViewController:picker animated:YES];
ライブラリを呼び出すには:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[picker setAllowsEditing:YES];
[self presentModalViewController:(UIViewController*)picker animated:YES];
完了すると、デリゲートメソッドが呼び出されます。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
ライブラリに画像を書き込むには、次を使用します。
UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);
または、フォトライブラリから選択した画像をに保存してUIImage
、さらにアクションを実行します。