zoukankan      html  css  js  c++  java
  • SDWebImage笔记

    SDWebImage  

    https://github.com/rs/SDWebImage

    提供一个UIImageView 类别以支持加载来自网络的远程图片。

    具有缓存管理,异步下载,同一个URL下载次数控制和优化等 

    UITableView UIImageView +webCache 类

    UIImageView +WebCache.h   tableView cellForRowAtIndexPath

    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cel = [tableView dequeReuseableCellWithIdentifier.MyIdentifier]

    if(cell == nil) {

      cell = 

    }

     

    [cell.imageView setImageWithURL:[NSURL URLWithString:@"htt://www.domain/path/to /image.jpg"]

    placeholderImage:[UIImage imageNamed:@"placeholder.png"];

    cell.textLabel.text = @"MyText";

    return cell;

    SDWebImageManager *manager = [SDWebImageManager sharedManager];

    UIImage *cacheImage = [manager imageWithURL:url];

    if(cachedImage) {

      

    } else {

      [manager downloadWithURL:url delegate:self];

    }

    protocol webImageManager:didFinishWithImage方法

    downloader= [SDWebImageDownloader downloaderWithURL:url delegate:self]

    独立的异步图片缓存

    SDWebImage支持异步的图片下载+缓存

    1 入口setImageWithURL:placeholderImage:option 先把placeholderImage显示后,

    然后SDWebImageManage根据URL开始处理图片

    进入SDWebImageManager-downloadWithURL:delegate:options:userinfo

    交给SDImageCache从缓存查找图片是否已下载

    queryDiskCacheForKey:delegate:userinfo

    先从内存图片查找是否有图片, 如果内存中已经有图片存,

    imageCach:didFindImage:forKey:userInfo

    如果内存中没有,生成NSInvocationOperation 到开始从硬盘查找图片图片是否已 存

    根据URLKey 在硬盘存目录下尝试读取图片,这是NSOperation操作,

    notifyDelegate

    imageCache:didNotFindImageForKey:userinfo

    共享或重新生成一个下载器SDWebImageDownloader开始下载图片。

    下载由NSURLConnection 来做,实现相关delegate 来判断图片下载中。

    connection:didReceiveData:中利用IMageIO做了按图片下载进度加载效果。

    connection:didFinishLoading 数据下载完成后交给SDWebImageDecoder做

    图片解码处理

    NSOperationQueue完成,不会拖慢主线程UI,

    notifyDelegateOnMainThreadWithInfo宣告解码完成,imageDecoder:didFinishDecodingImage:userInfo

    image

    保存到SDImageCache中, 内存存和硬盘缓存同时保存。

    NSInvocationOperation完成,

     

     

  • 相关阅读:
    牛客练习赛51 D题
    Educational Codeforces Round 72 (Rated for Div. 2) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Educational Codeforces Round 72 (Rated for Div. 2) B题
    Educational Codeforces Round 72 (Rated for Div. 2) A题
    《DSP using MATLAB》Problem 7.2
    《DSP using MATLAB》Problem 7.1
    《DSP using MATLAB》Problem 6.24
  • 原文地址:https://www.cnblogs.com/yushunwu/p/3133086.html
Copyright © 2011-2022 走看看