Giter Club home page Giter Club logo

sdimagecachewithgifdemo's Introduction

SDImageCacheWithGifDemo

A small app shows how to use FLAnimatedImage for animated GIF with SDWebImage .

As SDWebImage discussed here: Drop our GIF support and integrate a 3rd party solution This project modify two little parts of SDWebImage's source code. 1. I disable SDWebImage's gif code. ( just modify UIImage+MultiFormat.m 's line 22-26 )

+ (UIImage *)sd_imageWithData:(NSData *)data {
    UIImage *image;
    /*
    NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
    if ([imageContentType isEqualToString:@"image/gif"]) {
        image = [UIImage sd_animatedGIFWithData:data];
    }*/
    if (0) {
    }
#ifdef SD_WEBP

SDImageCache.h , add this function to public, so I can get the cached NSData

- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key;

The trick that I used to use FLAnimatedImage to animated gif is like this:

if imgurlstring.hasSuffix(".gif") {
    //we use NSData from the cache
    var data = SDWebImageManager.sharedManager().imageCache.diskImageDataBySearchingAllPathsForKey(imgurlstring)
    var img = FLAnimatedImage(animatedGIFData: data!)
    var imgview = FLAnimatedImageView(frame: CGRectMake(0, 0, self.baseview.frame.width, self.baseview.frame.height))
    imgview.animatedImage = img
    imgview.contentMode = UIViewContentMode.ScaleAspectFit
    self.baseview.addSubview(imgview)
} else {
    var pngview = UIImageView(image: image)
    pngview.frame = CGRectMake(0, 0, self.baseview.frame.width, self.baseview.frame.height)
    pngview.contentMode = UIViewContentMode.ScaleAspectFit
    self.baseview.addSubview(pngview)
}

For more details, just download the project. :]


2015-08-14 updated:

  1. SDWebImage was updated to 3.7.3

  2. Now use SDWebImageDownloader.sharedDownloader().downloadImageWithURL to do the download operation. Use SDWebImageManager.sharedManager().imageCache.storeImage to manually cache the downloaded image data.

  3. Add a clean cache button in storyboard.

sdimagecachewithgifdemo's People

Contributors

neil-wu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.