将NSDATA转换为UIImage时速度慢 [英] Slow speed while converting NSDATA to UIImage

查看:104
本文介绍了将NSDATA转换为UIImage时速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have some images in the array in the form of NSDATA.and i am showing them on page in page controller example 6 at a time.

但它们是花时间转换为UIImage,这就是为什么滚动得慢,我们还有其他选择吗?

But they are taking time to get convert in to UIImage that's why scrolling get slow dowwn is we have any other option?

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

i am using following code to convert them into NSDATA.

[UImage imageWithData:data];

[UImage imageWithData:data];

推荐答案

来自 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
}

这篇关于将NSDATA转换为UIImage时速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆