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

    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){

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值