iphone – 从照片库中选择多个图像

iphone – 从照片库中选择多个图像,第1张

概述我会问一个问题,也许已经被问了一百万次。 我正在制作iPad的应用程序,并希望让用户能够从其照片库中多次选择图像。我已经有一个工作代码供用户一次选择一个图像。 (不是我需要的) 我已经下载并查看了ELC图像采集器示例代码,但该代码与iOS 5或Xcode 4不兼容。即,它具有ARC和左右编译问题,其使用版本和dealloc遍及全部。 我很沮丧,苹果还没有为我们的开发人员在大多数iPhone / i 我会问一个问题,也许已经被问了一百万次。

我正在制作iPad的应用程序,并希望让用户能够从其照片库中多次选择图像。我已经有一个工作代码供用户一次选择一个图像。 (不是我需要的)

我已经下载并查看了ELC图像采集器示例代码,但该代码与iOS 5或Xcode 4不兼容。即,它具有ARC和左右编译问题,其使用版本和dealloc遍及全部。

我很沮丧,苹果还没有为我们的开发人员在大多数iPhone / ipad应用程序中为这个最常请求的功能创建内置API。 (不是一个,但多选图)

有没有其他示例代码可用?相信我,我一直在搜索一段时间。

解决方法 好的,我有这个想法。资产库的问题在于它为您提供了图像的所有GEO数据。对于使用您的应用程序的用户来说,这意味着他们会立即提示您的应用正在尝试访问其位置。实际上你想要做的就是让他们从他们的相册中选择多个图像。大多数用户将被视为盗版问题。最好的方法是使用imagePickerController的apple API。我知道它可以让您一次选择一个图片,但如果您添加以下代码,它将允许您选择多个图片。

我正在做的是让用户继续选择他们想要的照片,将这些文件保存在应用程序文档目录中,直到他们点击完成按钮。看到这里我的示例代码,希望它会为您节省经历资产库的痛苦

-(IBAction)selectExitingPicture{    //Specially for fing iPAD    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];    imagePicker.delegate = self;    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotolibrary;    imagePicker.mediaTypes = [NSArray arrayWithObject:(Nsstring *)kUTTypeImage];    popoverController = [[UIPopoverController alloc] initWithContentVIEwController:imagePicker];    [popoverController presentPopoverFromrect:CGRectMake(0.0,0.0,400.0,300.0)                              inVIEw:self.vIEw           permittedArrowDirections:UIPopoverArrowDirectionAny                            animated:YES];}//Done button on top- (voID)navigationController:(UINavigationController *)navigationController      willShowVIEwController:(UIVIEwController *)vIEwController                    animated:(BOol)animated{        //NSLog(@"InsIDe navigationController ...");    if (!donebutton)     {        donebutton = [[UIbarbuttonItem alloc] initWithTitle:@"Done"                                                      style:UIbarbuttonItemStyleDone                                                     target:self action:@selector(saveImagesDone:)];    }    vIEwController.navigationItem.rightbarbuttonItem = donebutton;}- (IBAction)saveImagesDone:(ID)sender{    //NSLog(@"saveImagesDone ...");    [popoverController dismisspopoverAnimated:YES];}-(voID)imagePickerController:(UIImagePickerController *)picker      dIDFinishPickingImage : (UIImage *)image                 editingInfo:(NSDictionary *)editingInfo{    //DONT disMISS    //[picker dismissModalVIEwControllerAnimated:YES];    //[popoverController dismisspopoverAnimated:YES];        IMAGE_COUNTER = IMAGE_COUNTER + 1;        imageVIEw.image = image;        // Get the data for the image        NSData* imageData = UIImageJPEGRepresentation(image,1.0);        // Give a name to the file        Nsstring* incrementedimgStr = [Nsstring stringWithFormat: @"UserCustomPotraitPic%d.jpg",IMAGE_COUNTER];        NSArray* paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);        Nsstring* documentsDirectory = [paths objectAtIndex:0];        // Now we get the full path to the file        Nsstring* fullPathTofile2 = [documentsDirectory stringByAppendingPathComponent:incrementedimgStr];        // and then we write it out        [imageData writetofile:fullPathTofile2 atomically:NO];}

//现在使用此代码获取用户选择的图片。在你的代码中从任何你想要的地方调用它

NSArray* paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES);        Nsstring* documentsPath = [paths objectAtIndex:0];        Nsstring* datafile = [documentsPath stringByAppendingPathComponent:@"UserCustomPotraitPic1.jpg"];        NSData *potraitimgData = [NSData dataWithContentsOffile:datafile];        backgroundImagePotrait = [UIImage imageWithData:potraitimgData];
总结

以上是内存溢出为你收集整理的iphone – 从照片库中选择多个图像全部内容,希望文章能够帮你解决iphone – 从照片库中选择多个图像所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1070984.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存