存储对相机胶卷中保存的图像的引用

发布于 2024-10-24 08:09:21 字数 319 浏览 2 评论 0原文

我一直在开发一个简单的应用程序,它允许用户拍照并将其存储在相机胶卷中以供以后使用。为此,我使用 UIImagePickerController 和 UIImageWriteToSavedPhotosAlbum 方法,该方法运行良好。

我的问题是:有什么方法可以将图像的路径存储在相机胶卷中,以便我以后可以使用它再次调用图像?或者,我是否必须将图像保存在应用程序中才能稍后再次使用?

如果有一种简单的方法可以做到这一点,那就太好了,因为在视频中,您只需存储特定视频的 NSUrl,然后调用 MPMoviePlayerController 为您完成所有操作。

任何帮助将不胜感激!

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?

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.

Any help would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放血 2024-10-31 08:09:21

事实证明,做到这一点其实并不难。在 UIImagePickerDelegate 方法中:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

NSDictionary“info”实际上包含存储在相机胶卷上的图像或电影的 url。您只需检查:

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.
}

,这会将电影保存到相机胶卷,并记录 url。对照片进行类似操作,只需将“kUTTypeMovie”替换为“kUTTypeImage”,然后替换

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.

UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];    
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

如果您需要将 UIImage 存储在相机胶卷上,则 stackoverflow 上有一篇很棒的文章 使用 NSCoding 保存 UIImage,您可以使用它在应用中存储图像。希望对某人有帮助!

It turns out that it is actually not that hard to do this. In the UIImagePickerDelegate method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

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.
}

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);

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文