我在数组中有一些 NSDATA 形式的图像。我一次在页面 Controller 示例 6 的页面上显示它们。
但是他们需要时间才能转换为 UIImage,这就是滚动速度变慢的原因,我们还有其他选择吗?
我正在使用以下代码将它们转换为 NSDATA。
[UImage imageWithData:数据];
最佳答案
在你的主线程中:
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage)
object:nil];
[queue addOperation:operation];
[operation release];
所需的其他方法:
- (void)loadImage {
NSData* imageData = //however you're getting your NSData
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
[imageData release];
[self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO];
}
- (void)displayImage:(UIImage *)image {
[imageView setImage:image]; //UIImageView
}
关于iphone - 将 NSDATA 转换为 UIImage 时速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7965283/