I use SDWebImage
to download images asynchronously to my UIImageView
s. Most images that received are of acceptable sizes, and can be easily downloaded, and set to the UIImageView
s.
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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With