2012-05-17 45 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是你所需要的。