如何将相机中的图像保存到iPhone图库中的特定文件夹?

嘿,我是新来的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 ie 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"]; 

任何来源或链接的参考是赞赏。 谢谢您的帮助!

你可以使用AssetsLibrary,这将解决你的问题。

 - (IBAction)takePhoto { UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; imagePickerController.editing = YES; imagePickerController.delegate = (id)self; [self presentModalViewController:imagePickerController animated:YES]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { [self.library saveImage:image toAlbum:@"Touch Code Magazine" withCompletionBlock:^(NSError *error) { if (error!=nil) { NSLog(@"Big error: %@", [error description]); } }]; [picker dismissModalViewControllerAnimated:NO]; } 

这已经在这里解释,一个很好的教程..

http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/