使用SDWebImage处理非常大的图像下载 [英] Handling download of very large images with SDWebImage

查看:65
本文介绍了使用SDWebImage处理非常大的图像下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 SDWebImage 将图像异步下载到我的 UIImageView 上.收到的大多数图像大小都可以接受,可以轻松下载并设置为 UIImageView s.

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.

但是有时候,URL上的源图像具有极高的分辨率(相对于我的 imageView 的大小-60x60).在这种情况下,永远不会设置图像.有时我的应用程序崩溃,有时却什么也没有发生(图像保持 nil ),在极少数情况下,我收到类似以下错误:无法分配400000字节的内存(我不完全确定确切的错误日志,对不起).

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).

例如,来自pinterest图标的图像Pinterest的网站本身非常庞大(10000 x 10000).我的 imageView 永远无法绘制该图像.目前,我已经硬编码将图像替换为,但我知道这是不好的做法.而且,这只是一种情况,可能有更多这样的图像可能会干扰用户体验.

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.

如何处理此类情况?

推荐答案

只需检查接收到的图像的大小,当其大小比imageview接受的大小大得多时,您可以调整图像的大小,并在此处链接调整图像的大小链接.调整大小后,您可以将其放置在imageview中.希望对您有帮助.

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.

这篇关于使用SDWebImage处理非常大的图像下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆