【问题标题】:Issue with ELC Image Picker when too many images are selected iPhoneIssue with ELC Image Picker when too many images are selected iPhone
【发布时间】:2012-05-17 07:45:29
【问题描述】:

我在我的项目中使用 ELC 图像选择器。这里我遇到了一个问题:

当我选择像 20 选择器这样的图像时工作正常,但是当我选择像 32(选择的图像计数)这样的图像时,我的应用在关闭控制器本身之前崩溃并且我收到错误:

节目接收信号:“0”。临时数据格式化程序 不可用,将在“继续”后重试。 (未知错误加载 共享库“/Developer/usr/lib/libXcodeDebuggerSupport.dylib”)

我也得到了:

收到内存警告。等级=1

注意:当这种情况发生时,首先我选择了 32 张工作正常的图像,然后我再次选择了相同数量的图像,它崩溃了。

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

谁能给我解决这个问题的答案?

【问题讨论】:

    标签: objective-c ios xcode ipad uiimagepickercontroller


    【解决方案1】:

    从错误中可以看出是内存问题

    所以你有两个选择

    1. 设置可以选择的图像数量限制
    2. 在后台将图像保存到临时文件夹

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

    【讨论】:

    • 感谢您的回复..但是当我试图将此转换为 nsdata 我得到 0 字节...你能告诉我如何将此 url 转换为图像
    • 你可以试试NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:@"assets-library://asset/asset.PNG?id=1000000015&ext=PNG] ); 可能有用
    • 我试过像 NSDictionary *dict = [info objectAtIndex:count]; //imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]]; NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@",[dict objectForKey:@"UIImagePickerControllerReferenceURL"]]]); imageview.image = [UIImage imageWithData:data];但得到 0 个字节
    【解决方案2】:

    @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就是你需要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      相关资源
      最近更新 更多