事实证明,实际上做到这一点并不难。在 UIImagePickerDelegate 方法中:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
NSDictionary“信息”实际上包含存储在相机胶卷上的图像或电影的 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.
}
这会将电影保存到相机胶卷,并记录网址。为照片做类似,只需将“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 Saving UIImage with NSCoding 上的一篇很棒的帖子将图像存储在您的应用中。希望对某人有所帮助!