您的位置:首页 > 其它

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

2016-11-24 09:44 1116 查看
    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 ([dict
objectForKey:UIImagePickerControllerMediaType] ==ALAssetTypeVideo){

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐