使用SDWebImage处理非常大的图像下载

编程入门 行业动态 更新时间:2024-10-26 10:28:11
本文介绍了使用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处理非常大的图像下载

本文发布于:2023-11-11 10:57:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578233.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:非常大   图像   SDWebImage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!