私は、iPhone ギャラリーにある写真を参照して表示する必要があるプロジェクトに取り組んでいます。
そのために ALAssetLibrary を使用します。サムネイル画像を生成するには、「aspectRatioThumbnail」を使用します。私の 3GS iOS 5 ではすべてがうまくスムーズに動作します。しかし、これらの方法は iOS4 には存在しません。
この関数を使用してサムネイル比率の画像を手動で生成しようとしましたが、メモリ警告のためにクラッシュしました。ログは、生成された画像サイズが最大サイズ 120 の指定された制約を尊重していないことを示しています。
何か案は ?
NSDate* firstDate = [NSDate date];
uint8_t* buffer = (Byte*)malloc(_asset.defaultRepresentation.size);
NSUInteger length = [_asset.defaultRepresentation getBytes:buffer fromOffset:0.0 length:_asset.defaultRepresentation.size error:nil];
NSData* data = [[NSData alloc] initWithBytesNoCopy:buffer length:_asset.defaultRepresentation.size freeWhenDone:YES];
nil];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
(id)kCFBooleanTrue, kCGImageSourceShouldAllowFloat,
(id)kCFBooleanTrue, kCGImageSourceCreateThumbnailWithTransform,
(id)kCFBooleanTrue, kCGImageSourceCreateThumbnailFromImageAlways,
[NSNumber numberWithInt:120], kCGImageSourceThumbnailMaxPixelSize,
nil];
CGImageSourceRef sourceRef = CGImageSourceCreateWithData((CFDataRef)data, (CFDictionaryRef) options);
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(sourceRef, 0, NULL);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, imageProperties);
image = [UIImage imageWithCGImage:imageRef];
NSTimeInterval tic = [[NSDate date] timeIntervalSinceDate:firstDate];
NSLog(@"Thumbnail generation from ios4 method %f [size %f * %f", tic, image.size.width, image.size.height);
[data release];
CFRelease(sourceRef);
CFRelease(imageRef);
CFRelease(imageProperties);