objective-csdwebimagecontentmode

Who change the image's size? SDWebImage or ContentMode


I use SDWebImage to set image like this:

    [self.imageView sd_setImageWithURL:topicModel.large_image] 
        placeholderImage:nil 
        options:0 
        progress:^(NSInteger receivedSize, NSInteger expectedSize) {

    } completed:^(UIImage *image, 
        NSError *error, 
        SDImageCacheType cacheType, 
        NSURL *imageURL) { 
}];

after this , i set the imageView's contentMode like this:

    if (topicModel.isBigPicture) {
        self.imageView.contentMode = UIViewContentModeTop;
        self.imageView.clipsToBounds = YES;
    }else {
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
        self.imageView.clipsToBounds = NO;
    }

the size of the imageView is (355, 200),
the size of the image is bigger than imageView, both width and height.

As we all know,
If the topicModel is bigPicture, the contentMode will be UIViewContentModeTop. UIViewContentModeTop remain same size, just positioned adjusted.

But i find a problem?
In my case, the size of image will convert to (300, XXX), XXX seems calculate by (image.realHeight * 300.0 / image.realWidth)
Actually i don't change the size of the image in my project.

Here is my question:
what's wrong with my code?
how to make the image's width same as the imageView's width?


Solution

  • Finally, I find the the answer.
    And the reason is that i use the newest version of SDWebImage

    Here is the solution :-)

    if you want get the original image, you must change the code in SDWebImage/SDWebImageDecoder.m like this:

        CGContextRelease(context);  
        //add this method
         UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef];
    
        //delete this method
         UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation];
      CGImageRelease(decompressedImageRef);  
    
        return decompressedImage;
      }
    

    if you want to know more details ,You can see the below link
    SDWebImage ---- Images from web-url too small when using v. 3.7.4 and above