嘿,我是 iPhone 的新手,最近一直在尝试制作应用程序。基本上,我的想法是如果用户从相机中拍摄了任何图像,则应该将其保存在设备图库中。我知道如何将照片保存在图库中,这对我来说没问题,但我在将所有捕获的图像保存到设备图库中的特定文件夹(例如一个新相册)方面遇到了麻烦。我希望用户能够拍摄多张照片,然后将那个特定文件夹中的图片复制到图库中。
以下是我的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
UIImage *photoTaken = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.imageView.image = photoTaken;
//Save Photo to library only if it wasnt already saved i.e. its just been taken
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(photoTaken, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
UIAlertView *alert;
if (error) {
alert = [[UIAlertView alloc] initWithTitle:@"Error!"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
我尝试使用以下代码,但我不知道它将图像保存到我的iPhone设备的应用程序资源的位置:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"EMS_FOLDER"];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
任何参考来源或链接都会受到赞赏。 感谢您的帮助!