2012-01-17 53 views
1

我嘗試使用我的應用程序ALAssetRepresentation。而當我環OM的圖像有幾個圖像的崩潰應用應用程序崩潰時,你得到fullResolutionImage

for(ALAsset *asset in _assets) { 
     NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init]; 
     [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"]; 

     ALAssetRepresentation *representation = [asset defaultRepresentation]; 

     if (!representation) { 
      [workingDictionary release]; 
      continue; 
     } 
     CGImageRef imageRef = [representation fullResolutionImage];//here the app crash 
      UIImage *img = [UIImage imageWithCGImage:imageRef]; 
    if (!img) { 
     [workingDictionary release]; 
     continue; 
    } 
    if (!img) { 
     [workingDictionary release]; 
     continue; 
    } 

    [workingDictionary setObject:img forKey:@"UIImagePickerControllerOriginalImage"]; 
    [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyOrientation] forKey:@"orientation"]; 

    [returnArray addObject:workingDictionary]; 
    [workingDictionary release];  
} 

在此行中我得到的碰撞沒有任何消息:

CGImageRef imageRef = [representation fullResolutionImage]; 

這是崩潰味精

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

回答

1

這是最有可能是由於耗盡內存,導致崩潰的圖像有多大?

+0

圖片所以需要每大,情侶MB的圖像 – MTA 2012-01-17 13:25:59

+0

這一切都取決於你對它們做了什麼,你是否正在使用它,清理使用的內存(如果你將它添加到任何數組等),然後移動到下一個...? – 2012-01-17 13:29:33

+0

我編輯我的帖子,你可以看到在循環中的變化 – MTA 2012-01-17 13:48:11

0

我有一個類似的問題,找誰解決了幾個小時之後,我發現這一點 - 太大資產錯誤的最佳解決方案:從圖像庫

// For details, see http://mindsea.com/2012/12/18/downscaling-huge-alassets-without-fear-of-sigkill 

#import <AssetsLibrary/AssetsLibrary.h> 
#import <ImageIO/ImageIO.h> 

// Helper methods for thumbnailForAsset:maxPixelSize: 
static size_t getAssetBytesCallback(void *info, void *buffer, off_t position, size_t count) { 
    ALAssetRepresentation *rep = (__bridge id)info; 

    NSError *error = nil; 
    size_t countRead = [rep getBytes:(uint8_t *)buffer fromOffset:position length:count error:&error]; 

    if (countRead == 0 && error) { 
     // We have no way of passing this info back to the caller, so we log it, at least. 
     NSLog(@"thumbnailForAsset:maxPixelSize: got an error reading an asset: %@", error); 
    } 

    return countRead; 
} 

static void releaseAssetCallback(void *info) { 
    // The info here is an ALAssetRepresentation which we CFRetain in thumbnailForAsset:maxPixelSize:. 
    // This release balances that retain. 
    CFRelease(info); 
} 

// Returns a UIImage for the given asset, with size length at most the passed size. 
// The resulting UIImage will be already rotated to UIImageOrientationUp, so its CGImageRef 
// can be used directly without additional rotation handling. 
// This is done synchronously, so you should call this method on a background queue/thread. 
- (UIImage *)thumbnailForAsset:(ALAsset *)asset maxPixelSize:(NSUInteger)size { 
    NSParameterAssert(asset != nil); 
    NSParameterAssert(size > 0); 

    ALAssetRepresentation *rep = [asset defaultRepresentation]; 

    CGDataProviderDirectCallbacks callbacks = { 
     .version = 0, 
     .getBytePointer = NULL, 
     .releaseBytePointer = NULL, 
     .getBytesAtPosition = getAssetBytesCallback, 
     .releaseInfo = releaseAssetCallback, 
    }; 

    CGDataProviderRef provider = CGDataProviderCreateDirect((void *)CFBridgingRetain(rep), [rep size], &callbacks); 
    CGImageSourceRef source = CGImageSourceCreateWithDataProvider(provider, NULL); 

    CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef) @{ 
                    (NSString *)kCGImageSourceCreateThumbnailFromImageAlways : @YES, 
                    (NSString *)kCGImageSourceThumbnailMaxPixelSize : [NSNumber numberWithInt:size], 
                    (NSString *)kCGImageSourceCreateThumbnailWithTransform : @YES, 
                   }); 
    CFRelease(source); 
    CFRelease(provider); 

    if (!imageRef) { 
     return nil; 
    } 

    UIImage *toReturn = [UIImage imageWithCGImage:imageRef]; 

    CFRelease(imageRef); 

    return toReturn; 
}