圖片大小調整和簡單的緩存iOS庫:GDRSImageCache
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;
}];
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!