iphone – 从照片库中选择多个图像
发布时间:2020-12-15 01:55:49 所属栏目:百科 来源:网络整理
导读:我会问一个问题,也许已经被问了一百万次。 我正在制作iPad的应用程序,并希望让用户能够从其照片库中多次选择图像。我已经有一个工作代码供用户一次选择一个图像。 (不是我需要的) 我已经下载并查看了ELC图像采集器示例代码,但该代码与iOS 5或Xcode 4不兼
我会问一个问题,也许已经被问了一百万次。
我正在制作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]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |