简体   繁体   English

iOS - 异步缓存和加载图像

[英]iOS - Caching and loading images asynchronously

I want an image loading and caching library for iOS that 我想要iOS的图像加载和缓存库

  • loads images asynchronously, 异步加载图像,
  • caches images, with a configurable cache size and LRU behaviour, 缓存图像,具有可配置的缓存大小和LRU行为,
  • checks to see if images have been updated, using HTTP HEAD, 使用HTTP HEAD检查图像是否已更新,
  • doesn't cache anything in the event of an error code or an invalid image. 如果出现错误代码或图像无效,则不会缓存任何内容。

I've looked at HJCache , but it only satisfies the first two of these criteria. 我看过HJCache ,但它只满足前两个标准。 Is there something better? 还有更好的东西吗?

I know that this thread has been answered, but I have tried a library that has worked great. 我知道这个帖子已经被回答,但我已经尝试了一个效果很好的库。 I was using ASIHttpRequest before and the difference is big. 我之前使用的是ASIHttpRequest,差别很大。

https://github.com/rs/SDWebImage https://github.com/rs/SDWebImage

Also, if someone needs to Resize or Crop the remote images, and have the same features that SDWebImage provide, I have integrated SDWebImage library with UIImage+Resize library (by Trevor Harmon), and created an example project. 此外,如果有人需要调整大小或裁剪远程图像,并具有SDWebImage提供的相同功能,我已将SDWebImage库与UIImage + Resize库(Trevor Harmon)集成,并创建了一个示例项目。 I modified the code of SDWebImage to deal with transformations (crop, resize). 我修改了SDWebImage的代码来处理转换(裁剪,调整大小)。

The project is public on https://github.com/toptierlabs/ImageCacheResize . 该项目在https://github.com/toptierlabs/ImageCacheResize上公开。 Feel free to use it! 随意使用它!

EDIT : ASI has been deprecated now but @Tony's answer has a link to a library that seems to do most of this (disclaimer - I've not yet tried it and am going by @Tony's recommendation!) 编辑:ASI现在已被弃用,但@Tony的答案有一个链接到一个似乎完成大部分工作的图书馆(免责声明 - 我还没有尝试过,而且正按照@Tony的推荐!)


ASIHTTPRequest does all of that :) ASIHTTPRequest完成所有这些:)

All you would have to do is add something like to the success callback 您所要做的就是添加类似于成功回调的内容

UIImage *image = [UIImage imageWithData:[request responseData]];

// If the image is nil ASIHTTPRequest will let you remove the data from the cache
// but I can't remember off the top of my head how. Checkout the docs!

EDIT 编辑

And when you've finished it, you could always pop it onto github for the rest of us . 当你完成它之后,你总是可以把它放到github上给我们其他人。 . .

I had a look recently for the sort of thing you describe -- either a general data cache, or an image centric one -- and didn't find much of interest. 我最近看了一下你描述的那种东西 - 无论是通用数据缓存还是以图像为中心的 - 并且没有引起太多兴趣。 So you may have to roll your own to get all those features. 因此,您可能需要自己动手才能获得所有这些功能。

There's a various blogs posts and things detailing such things, such as http://davidgolightly.blogspot.com/2009/02/asynchronous-image-caching-with-iphone.html . 有各种各样的博客文章和详细介绍这些内容的东西,例如http://davidgolightly.blogspot.com/2009/02/asynchronous-image-caching-with-iphone.html

I take it you've considered the Three20 library? 我认为你考虑过Three20图书馆? I don't think it would cover your requirements though. 我认为它不会满足你的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM