FastImageCache使用总结

看资料,好晕,自己写了个demo,总结一下

    func configFastImageCache(){
        var mutableImageFormats = [AnyObject]()
        let squareImageFormatMaximumCount = 400
        let squareImageFormatDevices:FICImageFormatDevices = [FICImageFormatDevices.Phone, FICImageFormatDevices.Pad]
        // 16 bgr
        let squareImageFormat16BitBGR = FICImageFormat(name: FICDPhotoSquareImage16BitBGRFormatName, family: FICDPhotoImageFormatFamily, imageSize: FICDPhotoSquareImageSize, style: FICImageFormatStyle.Style16BitBGR, maximumCount: squareImageFormatMaximumCount, devices: squareImageFormatDevices, protectionMode: FICImageFormatProtectionMode.None)
        mutableImageFormats.append(squareImageFormat16BitBGR)
        
        let sharedImageCache = FICImageCache.sharedImageCache()
        sharedImageCache.delegate = self
        sharedImageCache.setFormats(mutableImageFormats)
        
    }
    // ++++ FastImageCache FICImageCacheDelegate ++++++++++
    func imageCache(imageCache: FICImageCache!, wantsSourceImageForEntity entity: FICEntity!, withFormatName formatName: String!, completionBlock: FICImageRequestCompletionBlock!) {
        
        // Images typically come from the Internet rather than from the app bundle directly, so this would be the place to fire off a network request to download the image.
        // For the purposes of this demo app, we'll just access images stored locally on disk.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
            
            if let cd = entity as? FICDPhoto{
                let filePathURL = cd.sourceImageURLWithFormatName(formatName)
                let sourceData = NSData(contentsOfURL: filePathURL)
                let sourceImage = UIImage(data: sourceData!)
                
                dispatch_async(dispatch_get_main_queue(), {
                    completionBlock(sourceImage)
                })
            }
        }
    }
    func imageCache(imageCache: FICImageCache!, shouldProcessAllFormatsInFamily formatFamily: String!, forEntity entity: FICEntity!) -> Bool {
        return false
    }
    func imageCache(imageCache: FICImageCache!, errorDidOccurWithMessage errorMessage: String!) {
        print("\t AppDelegate \(#function) ++++++++++++++++++ \(errorMessage)")
    }
  • 使用
        imgView = UIImageView(frame: CGRectMake(10, 100, 100, 100))
        self.view.addSubview(imgView)
        
        let img = FICDPhoto()
        img.sourceImageURL = NSURL(string: "https://img.alicdn.com/bao/uploaded/i2/2836521972/TB2cyksspXXXXanXpXXXXXXXXXX_!!0-paimai.jpg")
        FICImageCache.sharedImageCache().retrieveImageForEntity(img, withFormatName: FICDPhotoSquareImage16BitBGRFormatName) { (entity:FICEntity!, fmt:String!, img:UIImage!) in
            if entity is FICDPhoto{
                self.imgView.image = img
            }
        }

转载于:https://my.oschina.net/asjoker/blog/710853

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值