poetryfar / AImage

A animated gif & apng engine for iOS in Swift. Optimized for Multi-Image case.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cover

Language Build Status CocoaPods Compatible Carthage compatible Pod License

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

video

##Features

  • Small but complete,only 250 lines of code.
  • As UIImage and UIImageView extension,easy to use.
  • Allow to control display quality, memory usage and display progress.
  • Optimized for multi-image case.
  • Have a great performance on memory and cpu usage.Using asynchronous image decoding to reduce the main thread CPU usage.

Installation

CocoaPods

You can use CocoaPods to install AImage by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'AImage'

To get the full benefits import AImage wherever you import UIKit

import UIKit
import AImage

Carthage

Create a Cartfile that lists the framework and run carthage bootstrap. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/AImage.framework to an iOS project.

github "wangjwchn/AImage"

Manually

  1. Download and drop /AImagefolder in your project.
  2. Congratulations!

Usage

/* Load gif or apng image as NSData */
let imageData = NSData(contentsOfURL:NSBundle.mainBundle().URLForResource("test", withExtension: "gif")!)

/*  Pass NSData into UIImage  */
let image = UIImage(AImageData:imageData!)

/* Pass UIImage into UIImageView */
let imageview = UIImageView(AImage: image)

/* Add view to root view */
imageview.frame = CGRect(x: 7.0, y: 50.0, width: 400.0, height: 224.0)
view.addSubview(imageview)

/* Start displaying animated image */
imageview.APlay();

...
...
...

/* Stop displaying animated image */
iamgeview.AStop();

Principles

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

CPU Usage[average] Memory Usage[average]/MB
AImage 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
AImage 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
AImage 38% ~ 81% [53%] 59.3 ~ 82.4 [63.3]
FLAnimatedImage 126% ~ 185% [143%] 58.4 ~ 98.9 [74.2]

###Display APNG:Compared with APNGKit

#####1.Display 1 Image

CPU Usage[average] Memory Usage[average]/MB
AImage (Cache) 2% ~ 44% [3%] 43.2 ~ 43.2 [43.2]
AImage (noCache) 20% ~ 49% [33%] 6.6 ~ 8.3 [7.5]
APNGKit (Cache) 1% ~ 42% [1%] 95.6 ~ 95.6 [95.6]
APNGKit (noCache) 1% ~ 26% [1%] 95.9 ~ 95.9 [95.9]

Measurement Factors:

  • Measurement time: April 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.

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

About

A animated gif & apng engine for iOS in Swift. Optimized for Multi-Image case.

License:MIT License


Languages

Language:Swift 96.0%Language:Ruby 4.0%