我正在使用 AssetsLibrary 开发一个照片库应用程序来加载我的设备照片。在另一个 VC 中呈现随机图像时,我注意到以下情况:我的完整 res 图像加载到 imageView 大约需要 1 或 2 秒(比本机 photosApp 长得多),我还从日志中得到“已接收加载几张图片后出现内存警告”。如果我将我的表示设置为 fullScreenImage 警告会停止,但我不想要这个。为了在视图上获得流畅的性能和高质量的图像,我必须进行哪些更改?
这是代码,希望你能告诉我问题是什么:
这是我想在屏幕上展示我的图像的 VC
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@",assetsController);
detailImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:detailImageView];
detailImageView.image = smallImage; //small image is my asset thumbnail and is passed as an argument in my init function
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ALAsset *asset = [assetsController.albumPics objectAtIndex:assetsController.index];
ALAssetRepresentation *representation = [asset defaultRepresentation];
bigImage = [[UIImage imageWithCGImage:[representation fullResolutionImage]]retain];
dispatch_async(dispatch_get_main_queue(), ^{
detailImageView.image = bigImage;
});
[pool release];
});
}
更新 1
{
UIImageView *detailImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:detailImageView];
detailImageView.image = smallImage;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ALAsset *asset = [assetsController.albumPics objectAtIndex:assetsController.index];
ALAssetRepresentation *representation = [asset defaultRepresentation];
UIImage *bigImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];
dispatch_async(dispatch_get_main_queue(), ^{
detailImageView.image = bigImage;
});
[pool release];
});
}