存储对相机胶卷中保存的图像的参考 [英] Storing a reference to an image saved in the Camera Roll
问题描述
我一直致力于一个简单的应用程序,它允许用户拍照并将其存储在相机胶卷中供以后使用。要做到这一点,我使用的是UIImagePickerController和方法UIImageWriteToSavedPhotosAlbum,它工作得很好。
I've been working on a simple application which allows the user to take a photo and store it in the camera roll for later use. To do this, I am using a UIImagePickerController, and the method UIImageWriteToSavedPhotosAlbum, which is working perfectly.
我的问题是:有没有办法存储图像的路径在相机胶卷中,以便我可以使用它稍后再次调用图像?或者,我是否必须将图像保存在应用程序中以便以后再次使用?
My question is: Is there any way to store the path to the image in the Camera Roll so that I can use that to call the image again later? Or, do I have to save the image in the app in order to use it again later?
如果有一种简单的方法可以做到这一点,那就好了,有一个视频,你只是存储特定视频的NSUrl,然后调用MPMoviePlayerController为你做所有事情。
It would be great if there was a simple way to do this, as there is with a video where you just store the NSUrl for the particular video, and then call MPMoviePlayerController to do everything for you.
任何帮助将不胜感激!
推荐答案
事实证明,实际上并不难做到这一点。在UIImagePickerDelegate方法中:
It turns out that it is actually not that hard to do this. In the UIImagePickerDelegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
NSDictionaryinfo实际上包含图像的url或存储在相机上的电影滚。您只需要检查:
the NSDictionary "info" actually contains the url to the image or the movie which is stored on the Camera Roll. You need only check:
if([[info valueForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]){ // If the user took a video,
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored.
UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); // Save the movie to the photo album.
}
这会将电影保存到相机胶卷,以及记录网址。为照片做它是类似的,只需用kUTTypeImage替换kUTTypeMovie,并替换
and this will save the movie to the Camera Roll, as well as record the url. Doing it for a photo is analogous, just replace the "kUTTypeMovie" with "kUTTypeImage", and replace
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored.
UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); // Save the movie to the photo album.
with
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
如果您需要将UIImage存储在相机胶卷上,那么stackoverflow上有一篇很棒的帖子< a href =https://stackoverflow.com/questions/1072700/iphone-why-does-the-documentation-say-uiimageview-is-nscoding-compliant>使用NSCoding保存UIImage 可用于将图像存储在您的应用中。希望能帮助别人!
If you need to store the UIImage not on the Camera Roll, there is a great post on stackoverflow Saving UIImage with NSCoding that you can use to store the image in your app. Hope that helps someone!
这篇关于存储对相机胶卷中保存的图像的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!