ELCImagePickerController

ELCImagePickerController

本文介绍了如何从UIImagePickerControllerReferenceURL获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 ELCImagePickerController ,但我不想保存所选的fullScreenImage到我的阵列中,因为如果我选择了40张iPad图像,那就不好了.

I am using ELCImagePickerController in my app and I don't want to save the selected fullScreenImage to my array because if i selected 40 iPad images then that is not good.

我想从UIImagePickerControllerReferenceURL而不是方法- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info的字典中获取UIImagePickerControllerOriginalImage数据.

I want to get data from UIImagePickerControllerReferenceURL instead of UIImagePickerControllerOriginalImage from the dict of method - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info.

我尝试过:

NSDictionary *dict = [info objectAtIndex:count];            

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dict objectForKey:@"UIImagePickerControllerReferenceURL"]]]];//UIImagePNGRepresentation([UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@",[dict objectForKey:@"UIImagePickerControllerReferenceURL"]]] );
        NSLog(@"length %d",[data length]);
        imageview.image = [UIImage imageWithData:data];

但是,每次我得到0个字节时.我已经尝试了论坛中所有可用的答案,但没有用.

However, every time I am getting 0 bytes. I have tried with all the answers available in forum but no use.

任何人都可以回答这个问题吗?

Can anyone answer this please?

推荐答案

UIImagePickerControllerReferenceURL返回NSURL对象而不是字符串对象.请将您的代码更改为-

UIImagePickerControllerReferenceURL returns NSURL object not the string object. Please change your code to -

NSData *data = [NSData dataWithContentsOfURL:[dict objectForKey:@"UIImagePickerControllerReferenceURL"]];
NSLog(@"length %d",[data length]);
imageview.image = [UIImage imageWithData:data];

UIImagePickerControllerReferenceURLAssets Library返回NSURL对象,因此可以将图像获取为-

UIImagePickerControllerReferenceURL returns NSURL object for Assets Library, so you can get image as -

ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:[[self.imagedata objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *rep = [asset defaultRepresentation];
    Byte *buffer = (Byte*)malloc(rep.size);
    NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
    NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
    [data writeToFile:photoFile atomically:YES];//you can save image later
} failureBlock:^(NSError *err) {
    NSLog(@"Error: %@",[err localizedDescription]);
}];

注意:iOS 9中不推荐使用ALAssetsLibrary.

这篇关于如何从UIImagePickerControllerReferenceURL获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:55