저는 보드 게임의 배경 이미지를 사용하는 간단한 퍼즐 게임을하고 있습니다. 모든 것이 잘 작동하지만 나를 귀찮게하는 것이 있습니다. 사진을 카메라에서 가져 와서 사진 라이브러리에 저장할 수는 있지만 저장 한 위치를 모릅니다. 내 사진의 URL은 정확히 무엇입니까? 여기 내 사진 라이브러리에 저장된 사진의 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];
}
URL을 반환하지 않습니다 UIImageWriteToSavedPhotosAlbum
호출 방법 및 변수 인스턴스 내가의를 통해 직접 사진 라이브러리를하지 호출하는 경우 info
그냥 URL을 가지고 카메라.
아무도 내가 그것을 고칠 수있는 방법을 알고 있습니까?
정말로 사진 라이브러리에 이미지를 저장 하시겠습니까? 나중에 참조 할 수 있도록 앱의 샌드 박스에 이미지를 저장하지 않으시겠습니까? – rmaddy
예, 사진 보관함에 저장해야합니다. –