Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling download of very large images with SDWebImage

I use SDWebImage to download images asynchronously to my UIImageViews. Most images that received are of acceptable sizes, and can be easily downloaded, and set to the UIImageViews.

However there are times, when the source image at the URL is of insanely high resolution (relative to the size of my imageView - 60x60). In such cases, the image is never set. Sometimes my app crashes, sometimes, nothing happens (image stays nil), and in a very rare case I received an error something like : Unable to allocate 400000 bytes of memory (I am not entirely sure of the exact error log, I apologise).

For example, this image of the pinterest icon from Pinterest's site itself is enormous (10000 x 10000). My imageView can never plot this image. For the time being, I have hardcoded to replace the image with this, but I know this is bad practice. Also, this is just one case, there might be infinitely more images such as this that might screw with the user experience.

How can I handle such cases ?

like image 932
n00bProgrammer Avatar asked Nov 01 '22 22:11

n00bProgrammer


1 Answers

Just put a check for size of image that you receive and when size much greater than what your imageview would accept then you could resize the image ,and here link for resizing the image link. After resizing then you could place it in imageview. Hope helpful for you.

like image 58
nikhil84 Avatar answered Nov 15 '22 05:11

nikhil84