ELCImagePickerController 同时选择多张图片时,获取文件名称

来源:互联网 发布:手机排课软件 编辑:程序博客网 时间:2024/05/11 16:02

    for (NSDictionary *dictin info) {

        if ([dictobjectForKey:UIImagePickerControllerMediaType] ==ALAssetTypePhoto){

            if ([dictobjectForKey:UIImagePickerControllerOriginalImage]){

                UIImage* image=[dictobjectForKey:UIImagePickerControllerOriginalImage];

                [images addObject:image];

                //获取图片名称

                __blockNSString *imageName = [NSStringnew];

                ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){

                    

                    ALAssetRepresentation *representation = [myassetdefaultRepresentation];

                    

                    imageName = [representation filename];

                    

                    NSLog(@"fileName : %@",imageName);

                };

                //注意这个地方,网上大多数用的是系统的类,单张选中,所以这个地方会是info,所以如果直接网上复制的代码,运行之后,会报错,需要改成dict

                NSURL *imageURL = [dictvalueForKey:UIImagePickerControllerReferenceURL];

                

                ALAssetsLibrary* assetslibrary = [[ALAssetsLibraryalloc]init];

                [assetslibrary assetForURL:imageURL

                               resultBlock:resultblock

                              failureBlock:nil];

                [selfdismissViewControllerAnimated:YEScompletion:^{

                    

                    

                    //获取图片的类型前的名字,将字符串切割操作

                    NSString *imagePath = [[imageNamecomponentsSeparatedByString:@"."]

                                           firstObject];

                    NSString *aPath=[NSStringstringWithFormat:@"%@/Documents/%@.jpg",

                                     NSHomeDirectory(),imagePath];

                    NSData *imgData =UIImageJPEGRepresentation(image,0);

                   //将图片写入沙盒

                    [imgData writeToFile:aPathatomically:YES];  

                    NSLog(@"path == %@ ==%@",imagePath,aPath);

                }];

                

                } else {

                NSLog(@"UIImagePickerControllerReferenceURL = %@", dict);

            }

        } elseif ([dictobjectForKey:UIImagePickerControllerMediaType] ==ALAssetTypeVideo){

}

0 0
原创粉丝点击