iphone - 将 NSDATA 转换为 UIImage 时速度慢

标签 iphone objective-c ios

我在数组中有一些 NSDATA 形式的图像。我一次在页面 Controller 示例 6 的页面上显示它们。

但是他们需要时间才能转换为 UIImage,这就是滚动速度变慢的原因,我们还有其他选择吗?

我正在使用以下代码将它们转换为 NSDATA。

[UImage imageWithData:数据];

最佳答案

来自http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation :

在你的主线程中:

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/

相关文章:

ios - 使用点击手势选择行

iphone - 旋转 UIImageView 将图像移出屏幕

iphone - Apple Mach-O-linker 错误?

ios - 在 [NSString stringWithContentsOfURL :url]; 之后,选项卡 Controller 卡住并且手机变得迟钝

ios - 是否需要将我的应用程序设置为 "universal"才能获得 AppStore 批准?

ios - 使用不兼容类型 void 的表达式初始化 NSArray *_strong

iphone - 从设备中检索序列号

ios - 如何清除 UIWebView/WKWebView 的内容?

ios - UITableView 中的多个 Nib 文件

iphone - 从应用委托(delegate)访问 viewController 属性