Skip to content

ACFancy/JWAnimatedImage

 
 

Repository files navigation

Cover Language Build Status CocoaPods Compatible Carthage compatible Pod License

An animated GIF engine for iOS in Swift with low memory & cpu usage.

video

##Features

  • Optimized for Multi-Image case.[New]
  • As UIImage and UIImageView extension,easy to use.
  • Have a great performance on memory usage by using producer/consumer pattern.
  • Have a great performance on CPU usage by using asynchronous loading.
  • Allow to control display quality by using factor 'level of Integrity'
  • Allow to control memory usage by using factor 'memoryLimit'

##Installation ######With CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
pod 'JWAnimatedImage'

######With Carthage

github "wangjwchn/JWAnimatedImage"

##How to Use

let url = NSBundle.mainBundle().URLForResource(“imagename”, withExtension: "gif")!
let imageData = NSData(contentsOfURL:url)
let image = UIImage()
image.AddGifFromData(imageData!)
let gifmanager = JWAnimationManager(memoryLimit:20)
let imageview = UIImageView()
imageview.AddGifImage(image,manager:gifmanager)
imageview.frame = CGRect(x: 0.0, y: 5.0, width: 400.0, height: 200.0)
view.addSubview(imageview)

##Architecture Architecture

####UIImageView State:

LifeCycle

##Benchmark:Compared with FLAnimatedImage ###1.Display 1 Image

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage 6% ~ 14% [8%] 7.5 ~ 8.4 [8.2]
FLAnimatedImage 8% ~ 24% [11%] 7.3 ~ ??? [???]

###2.Display 3 Images

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage 31% ~ 44% [38%] 12.4 ~ 13.4 [12.9]
FLAnimatedImage 36% ~ 62% [54%] 11.0 ~ 12.4 [11.3]

###3.Display 30 Images

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage 38% ~ 81% [53%] 59.3 ~ 82.4 [63.3]
FLAnimatedImage 126% ~ 185% [143%] 58.4 ~ 98.9 [74.2]

NOTE:

1.Measurement Factors:

  • Last updated: March 26, 2016

  • Measurement device: iPhone6 with iOS 9.3

  • Measurement tool: Profile in Xcode 7.3

  • Measurement image: See it in repository, all the parameters are default.

  • Raw data are here.

2.I've discussed the high memory usage of FLAnimatedImage with @mitchellporter and confirmed this problem does exist,as described here.

3.For each image, FLAnimatedImage creates a new independent thread. From the graph, we can see there are 36 threads when loading 30 GIFs, which causes a heavy CPU usage.

##Licence JWAnimatedImage is released under the MIT license. See LICENSE for details.

About

A animated GIF engine for iOS in Swift. Optimized for Multi-Image case.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 97.3%
  • Ruby 2.7%