图片大小调整和简单的缓存iOS库:GDRSImageCache

jopen 11年前

GDRSImageCache就一个简单的缓存和图片大小调整iOS库。通过一个 URL 该库会通过后台线程获取图片并在内存中缓存。 GDRSImageCache提供一个过滤模块,会将从获取的图片进行调整,然后再进行缓存。

以下是GDRSImageCache的一个典型用法:

UIImageView *anImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];    // create the cache  GDRSImageCache *cache = [[GDRSImageCache alloc] initWithCachedImageFilter:^UIImage *(UIImage *sourceImage) {        // resize the image to the image view size and round the image corners;       // this is called by the cache on a background thread      return [sourceImage gdrs_resizedImageToAspectFitSize:anImageView.bounds.size cornerRadius:10];    }];    // set the default image, which will be returned from  // fetchImageWithURL:completionHandler: if an image coresponding to the  // requested url is not cached yet.  cache.defaultImage = [UIImage imageNamed:<#place holder image name#>];      NSURL *imageUrl = <#an url to a image#>;    // fetch an image; the call returns imidiatly and the callback handler  // is called when the image is fetched over the network  anImageView.image = [cache fetchImageWithURL:imageUrl completionHandler:^(UIImage *image, NSError *error) {      anImageView.image = image;  }];

项目主页:http://www.open-open.com/lib/view/home/1400053036567