Slow speed while converting NSDATA to UIImage

前端 未结 1 1653
臣服心动
臣服心动 2021-01-28 15:22

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

相关标签:
1条回答
  • 2021-01-28 15:36

    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
    }
    
    0 讨论(0)
提交回复
热议问题