HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何将图像从相机保存到iPhone库中的特定文件夹?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
嘿,我是iPhone新手,我最近一直试图制作应用程序.基本上,我想要做的是如果用户将从相机捕获任何图像,那么它应该保存在设备库中.我知道如何在照片库中保存照片,这对@L_673_2@用,但我无法将所有捕获的图像保存到设备库中的特定文件夹(如新专辑)中.我希望用户能够拍摄多张照片,然后将该特定文件夹中的照片复制到图库中.

这是我的代码

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];

    if([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
        UIImage *pho@R_435_10586@ken = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

        self.imageView.image = pho@R_435_10586@ken;

        //Save Photo to library only if it wasnt already saved i.e. its just been taken
        if (picker.sourCEType == UIImagePickerControllersourceTypeCamera) {
            UIImageWriteToSavedPhotosAlbum(pho@R_435_10586@ken,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设备中的App资源:

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/

大佬总结

以上是大佬教程为你收集整理的ios – 如何将图像从相机保存到iPhone库中的特定文件夹?全部内容,希望文章能够帮你解决ios – 如何将图像从相机保存到iPhone库中的特定文件夹?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。