Skip to content

High-performance animation image library.

License

Notifications You must be signed in to change notification settings

noppefoxwolf/AnimatedImage

Repository files navigation

AnimatedImage

High-performance animation image library.

Install

let package = Package(
    dependencies: [
        .package(url: "https://github.com/noppefoxwolf/AnimatedImage", from: "0.0.x")
    ],
)

How It Works

AnimatedImage pre-decodes and caches all animation frames. Optimize the number of drawing frames from the drawing size and drawing timestamp to prevent the cache size from becoming too large. It is designed so that all processing does not depend on the MainActor.

Usage

UIKit

let imageView = AnimatedImage(frame: .null)
let image = APNGImage(data: data)
imageView.image = image
imageView.startAnimating()

SwiftUI

@State var image = GIFImage(data: data)

var body: some View {
    AnimatedImagePlayer(image: image)
}

Features

Low access main actor

Support playback APNG, GIF, WebP

Automatically adjust playback quality

Synchronize frame update

Customizable playback format

public final class ManualAnimatedImage: AnimatedImage {
    public let name: String
    let images: [CGImage]
    
    public init(name: String = UUID().uuidString, images: [CGImage]) {
        self.name = name
        self.images = images
    }
    
    public nonisolated func makeImageCount() -> Int {
        images.count
    }
    
    public nonisolated func makeDelayTime(at index: Int) -> Double {
        0.1
    }
    
    public nonisolated func makeImage(at index: Int) -> CGImage? {
        images[index]
    }
}

Required

  • Swift 6.0
  • iOS 16

Apps Using

License

AnimatedImage is available under the MIT license. See the LICENSE file for more info.

About

High-performance animation image library.

Topics

Resources

License

Stars

Watchers

Forks

Languages