Manish Jain
Manish Jain

Reputation: 865

Slow speed while converting NSDATA to UIImage

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.

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

i am using following code to convert them into NSDATA.

[UImage imageWithData:data];

Upvotes: 0

Views: 1310

Answers (1)

user684934
user684934

Reputation:

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

In your main thread:

NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] 
                                      initWithTarget:self
                                                 selector:@selector(loadImage) 
                                                    object:nil];
[queue addOperation:operation]; 
[operation release];

Other methods required:

- (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
}

Upvotes: 1

Related Questions