Coder Social home page Coder Social logo

autoloadimageview's Introduction

AutoLoadImageView

a lightweight image downloader,you can get detail infomation here:

http://www.kyson.cn/index.php/archives/4/

image

本框架相关的知乎上的回答引用:

我先扫个盲,大概说一下图片下载的原理: 大家知道,不一样的图片肯定有不一样的url,你可以这么理解:http://xxx.com/1.png (以下简称图片1)和 http://xxx.com/2.png(以下简称图片2) 肯定是两个不一样的图片。这个不难理解吧。然后继续,既然图片1和图片2 不一样,那么如果图片1已经下载到本地了,如何确保第二次不要再去下载图片1 呢,这里就涉及到缓存的概念了。我们要在本地将图片1缓存起来,然后第二次如果要下载图片1那就先去本地看看有没有图片1,如果有的话就直接从本地读取,没有的话再去下载。这个应该也不难理解了。 最后的难点就是我们怎么知道图片1已经下载过了,然后第二次就不用下载呢。前面已经说过了,既然不一样的url对应不一样的图片,那我们将图片缓存到本地的时候直接使用url作为文件名不就可以了么。对的,原理是这个原理,但你要知道url是带有类似冒号和斜杠等特殊字符的字符串,所以作为文件名肯定是不合适的,那么这个时候我们可以通过一对一加密来实现。 大概意思就是,如果url是唯一的,那么加密后的字符串也是唯一的,那么基本上就能唯一确定到这张图片了。这样的加密算法还是很多的,但能生成作为文件名的算法又比较好用的就是MD5加密了。 至于你说的情况,其实按道理在真实情况下是不会出现的。你可以这么思考,如果一个轮播图,上面的5张图片都是一样的,那这个轮播又有什么意义呢。但是,既然你提出来这个问题了,我也适当的说一下,其实解决的办法的思路无非是你每次下载图片的时候将图片url存到一个字典里或者数组里,然后再次下载的时候先去字典或者数组里找一下,如果有的话就不下载,静静等待下载完,否则就下载。 说了这么多原理,如果您还有疑问的话可以参考一下我写的文件下载器:zjh171/AutoLoadImageView · GitHub 这个图片下载器是相较于SDWebImage一个轻量级的实现,但一定能让你很简单的了解到下载图片,缓存图片的整个过程。图片下载器的相关文档可以在我的博客里找到:AutoloadImageView(kysonFramework之图片下载器(附带压缩功能) - Hello World) ,因为是英文的,如果有任何疑问的话欢迎提出来,或者联系我。

以上 作者:朱朱 链接:https://www.zhihu.com/question/22163365/answer/50434520 来源:知乎 著作权归作者所有,转载请联系作者获得授权。

autoloadimageview's People

Contributors

zjh171 avatar

Stargazers

Patrick avatar  avatar  avatar 冀磊  avatar Wayne avatar

Watchers

James Cloos avatar  avatar

Forkers

wendy006

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.