【发布时间】:2013-03-12 09:49:11
【问题描述】:
我正在使用 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];
});
}
【问题讨论】:
-
尝试发布[bigImage release];之后 detailImageView.image = bigImage;
-
@bhuXan 已经尝试过了,但在加载一些图像后仍然收到警告...
-
使用 jpeg 图像或将 png 转换为 jpeg 应该可以......
-
这只是一种预感,但如果你
NSLog是一项资产,你会得到什么?它看起来像 Core Data 对象吗? -
@Tommy 我登录时的输出是:Photo_Share[1420:907] 请参阅资产:ALAsset - 类型:照片,URLs:assets-library://asset/asset.JPG?id =00000000-0000-0000-0000-000000000072&ext=JPG
标签: ios multithreading grand-central-dispatch alassetslibrary nsautoreleasepool