ボード ゲームの背景として画像を使用する単純なパズル ゲームに取り組んでいます。すべて正常に動作しますが、少し気になることがあります。カメラで写真を撮ると、フォト ライブラリに保存できますが、どこに保存されたのかわかりません。つまり、写真の正確な URL は何ですか。
写真を保存するコードは次のとおりです。
- (void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToSave;
// Handle a still image capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {
editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
if (editedImage) {
imageToSave = editedImage;
} else {
imageToSave = originalImage;
}
CGRect bounds;
bounds.origin = CGPointZero;
bounds.size = imageToSave.size;
[scrollView setContentSize:bounds.size];
[scrollView setContentOffset:bounds.origin];
[imageView setFrame:bounds];
imageView.image = imageToSave;
if ([info objectForKey:@"UIImagePickerControllerReferenceURL"] == nil) {
// Save the new image (original or edited) to the Camera Roll
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
ALAssetOrientation orientation; //= [[[info objectForKey:@"UIImagePickerControllerMediaMetadata"] objectForKey:@"Orientation"] integerValue];
NSString *infoOrientation = [[info objectForKey:@"UIImagePickerControllerMediaMetadata"] objectForKey:@"Orientation"];
switch ([infoOrientation integerValue]) {
case 3:
orientation = ALAssetOrientationUp;
break;
case 6:
orientation = ALAssetOrientationRight;
break;
default:
orientation = ALAssetOrientationDown;
break;
}
[al writeImageToSavedPhotosAlbum:[imageToSave CGImage] orientation:orientation completionBlock:^(NSURL *assetURL, NSError *error) {
if (error == nil) {
NSLog(@"saved");
savedImageCam = assetURL;
} else {
NSLog(@"error");
}
}];
} else {
NSLog(@"URL from saved image: %@", savedImageCam);
NSLog(@"URL from photo image: %@", [info objectForKey:@"UIImagePickerControllerReferenceURL"]);
}
}
// Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSString *moviePath = (NSString *)[[info objectForKey:UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
call メソッドUIImageWriteToSavedPhotosAlbum
は URL を返さinfo
ず、カメラ経由ではなくフォト ライブラリを直接呼び出すと、インスタンス変数が URL を返すだけです。
どうすれば修正できるか知っている人はいますか?