2012-05-17 42 views
0

我在我的项目中使用ELC图像选择器。在这里我得到一个问题是:当选择了太多图像时,ELC图像选择器出现问题iPhone

当我选择像20拾取器的图像工作正常,但是当我选择图像像32(选定的图像数)我的应用程序崩溃之前解雇控制器本身,我得到错误:

Program received signal: “0”. Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")

而且也是我越来越:

Received memory warning. Level=1

注:当这种情况发生的就是,首先我选择了32幅图像工作得很好,并再次我选相同数量的它崩溃图像。

我也试过这个例子:github ELCImagePickerController project

任何人都可以给我答案来过来吗?

回答

3

从错误你可以看到,它的内存问题

所以,你有2个选项

  1. 设置图像的数量可以选用
  2. 背景图片保存到临时文件夹
  3. 限制

OR

自定义ELC选择器代码,以便塔t ...当一个人选择一个图像时......它将只采用图像路径,而不是图像内容 ,当它们完成时...现在运行一个循环以将这些图像存入您的应用程序。

+0

感谢您的答复..但从ELCPickerController我得到图像路径广告“assets-library://asset/asset.PNG?id = 1000000015&ext = PNG”,当我试图将其转换为nsdata我我得到0字节...你能告诉我如何将这个URL转换为图像 –

+0

你可以尝试像'NSData * data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:@“assets-library://asset/asset.PNG?id = 1000000015&ext = PNG]);' 可能工作 – cnu

+0

我试过像NSDictionary * dict = [info objectAtIndex:count]; \t \t \t \t \t \t // imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]]; (UIImage imageWithContentsOfFile:[NSString stringWithFormat:@“%@”,[dict objectForKey:@“UIImagePickerControllerReferenceURL”]]]);} [ \t \t \t imageview.image = [UIImage imageWithData:data];但获得0个字节 –

0

@SteveGear以下代码将解决您的问题。只需提供UIImagePickerControllerReferenceURL,你就可以得到NSData。它很长一段时间,但仍然可以帮助别人。

ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init]; 
NSURL *assetURL = [infoObject objectForKey:UIImagePickerControllerReferenceURL]; 
__block NSData *assetData; 

[assetLibrary assetForURL:assetURL resultBlock:^(ALAsset *asset) // substitute assetURL with your url 
{ 
    ALAssetRepresentation *rep = [asset defaultRepresentation]; 
    Byte *buffer = (Byte*)malloc((long)rep.size); 
    NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:(NSUInteger)rep.size error:nil]; 
    assetData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData what you need. 
    //[data writeToFile:assetData atomically:YES]; //Uncomment this if you want to store the data as file. 
} 
      failureBlock:^(NSError *err) { 
       NSLog(@"Error: %@",[err localizedDescription]); 
}]; 

这里assetData是你所需要的。