Ben fullScreenImage veya fullResolutionImage hayranı değilim. Bunu bir sıradaki birden çok öğe üzerinde yaptığınızda, UIImage'ı hemen serbest bıraksanız bile, bellek kullanımının önemli ölçüde artacağını ve bunu yapmaması gerektiğini fark ettim. Ayrıca fullScreenImage veya fullResolutionImage kullanıldığında, döndürülen UIImage hala sıkıştırılır, yani ilk kez çekilmeden önce sıkıştırılmış olacak, böylece UI'nizi engelleyecek ana iş parçacığı olacaktır.
Bu yöntemi kullanmayı tercih ediyorum.
-(UIImage *)fullSizeImageForAssetRepresentation:(ALAssetRepresentation *)assetRepresentation
{
UIImage *result = nil;
NSData *data = nil;
uint8_t *buffer = (uint8_t *)malloc(sizeof(uint8_t)*[assetRepresentation size]);
if (buffer != NULL) {
NSError *error = nil;
NSUInteger bytesRead = [assetRepresentation getBytes:buffer fromOffset:0 length:[assetRepresentation size] error:&error];
data = [NSData dataWithBytes:buffer length:bytesRead];
free(buffer);
}
if ([data length])
{
CGImageSourceRef sourceRef = CGImageSourceCreateWithData((__bridge CFDataRef)data, nil);
NSMutableDictionary *options = [NSMutableDictionary dictionary];
[options setObject:(id)kCFBooleanTrue forKey:(id)kCGImageSourceShouldAllowFloat];
[options setObject:(id)kCFBooleanTrue forKey:(id)kCGImageSourceCreateThumbnailFromImageAlways];
[options setObject:(id)[NSNumber numberWithFloat:640.0f] forKey:(id)kCGImageSourceThumbnailMaxPixelSize];
//[options setObject:(id)kCFBooleanTrue forKey:(id)kCGImageSourceCreateThumbnailWithTransform];
CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(sourceRef, 0, (__bridge CFDictionaryRef)options);
if (imageRef) {
result = [UIImage imageWithCGImage:imageRef scale:[assetRepresentation scale] orientation:(UIImageOrientation)[assetRepresentation orientation]];
CGImageRelease(imageRef);
}
if (sourceRef)
CFRelease(sourceRef);
}
return result;
}
Böyle kullanabilirsiniz:
// Get the full image in a background thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
UIImage* image = [self fullSizeImageForAssetRepresentation:asset.defaultRepresentation];
dispatch_async(dispatch_get_main_queue(), ^{
// Do something with the UIImage
});
});
tüm ince ve bu kod benim uygulamada da tüm görüntüleri cezası sağlamak çalışma görünüyor bu kodu seçin. Alınan varlıkların sıfır olacağını ya da bu kodla ilgili bir sorun olmadığını söyleyebilirim. –