Reputation: 2189
I do not want to download the image from the server until the user selects it. I want to show the thumbnails for the image. How to get thumbnails? I am able to download the full image using the URL from the server.
If the image at server is of say 1MB, how to get its thumbnail version?
Upvotes: 1
Views: 3074
Reputation: 27428
You can't make changes to server from your ios device
. you can just put data to server or fetch data from it. so, if big image is stored at server then you can't make it thumbnail from ios. you can just download it, once image comes to your device then you can modify it according to your need.
So, it is better way to keep two copies of same image to server and it is not hard task from server side. :)
Upvotes: 1
Reputation: 4402
There are two ways to achieve your goal :
Way 1:
You can not get thumbnail. If you have file of size say 1 MB then you have to downloaded it using SDWebImage
. When download completes create thumbnail of image. Now you can remove image of 1MB.
Code for create thumbnail :
+ (UIImage *)imageWithImage:(UIImage *)image scaledToFillSize:(CGSize)size
{
CGFloat scale = MAX(size.width/image.size.width, size.height/image.size.height);
CGFloat width = image.size.width * scale;
CGFloat height = image.size.height * scale;
CGRect imageRect = CGRectMake((size.width - width)/2.0f,
(size.height - height)/2.0f,
width,
height);
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
[image drawInRect:imageRect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Way 2:
At server side you have to keep both image original image and thumbnails. And so first load thumbnail using SDWebImage
. When user click on thumbnail get original image from server using SDWebImage
.
Upvotes: 3
Reputation: 9898
When you have absolute URL and just want to display image using SDWebImage.
Use below code
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:[NSURL URLWithString:strDisplayURL]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image)
{
dispatch_async(dispatch_get_main_queue(), ^{
profileImageView.image = image;
});
}
}];
Use image modes.
And make corner radius half of image view height or width. so it will become circle image view.
Upvotes: 0