Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SdWebImage download thumbnail and then download high resolution

I want to set a thumbnail image url and high res image url so that first thumbnail image is downloaded and then the high res image is downloaded

like image 954
Rajat Talwar Avatar asked Dec 21 '22 13:12

Rajat Talwar


1 Answers

Actually, you don't need to create any hidden UIImageView to do the trick.

What you must do is set the first URL (with the smaller image) to be directly downloaded into your UIImageView, and then use SDWebImageManager to download the larger version on the background. When it finishes download, simply set the downloaded image in your image view.

Here's how you can do that:

// First let the smaller image download naturally
[self.imageView setImageWithURL:self.imageURL];

// Slowly download the larger version of the image
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:self.currentPhoto.largeImageURL options:SDWebImageLowPriority progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
    if (image) {
        [self.imageView setImage:image];
    }
}];

Note how I used SDWebImageLowPriority option. This way, the image (which should be naturally larger than the first one) will be downloaded in a low priority and should not cancel the first download.

like image 167
Gui Moura Avatar answered May 03 '23 17:05

Gui Moura