Kapng-Android/README.md

67 lines
2.0 KiB
Markdown
Raw Normal View History

2018-11-15 19:45:27 +00:00
# Kapng-Android
2020-04-20 15:20:35 +00:00
### An android library to create or display apng
2018-10-05 19:51:13 +00:00
2020-04-20 15:20:35 +00:00
# Example of apng :
2018-10-05 19:51:13 +00:00
![apng-example](https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png)
2020-04-20 15:20:35 +00:00
# How to use this library :
2018-10-05 19:51:13 +00:00
2020-04-20 15:20:35 +00:00
## To load an animated png to an imageView :
2018-10-05 19:51:13 +00:00
```kotlin
2020-04-20 15:20:35 +00:00
val imageUrl = "https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png"
2018-10-05 19:51:13 +00:00
2020-04-20 15:20:35 +00:00
ApngDecoder.decodeApngAsyncInto(context, URL(url), imageView)
2018-10-05 19:51:13 +00:00
```
2020-04-20 15:20:35 +00:00
You can load a file, an uri, a ressource int, an url, or an inputStream.
2018-10-23 14:55:49 +00:00
2020-04-20 15:20:35 +00:00
## With a callback :
2018-10-23 14:55:49 +00:00
```kotlin
2020-04-20 15:20:35 +00:00
ApngDecoder.decodeApngAsyncInto(this, uri, viewerImageView, callback = object : ApngDecoder.Callback {
override fun onSuccess(drawable: Drawable) { println("Success !") }
override fun onError(error: Exception) { println("Error : $error") }
})
```
## To create animated png :
```kotlin
val output : OutputStream = FileOutputStream("res.png") // An OutputStream (ex : a FileOutputStream)
val maxWidth : Int = 256 // The width of your image (ex : 256)
val maxHeight : Int = 256// The height of your image (ex : 256)
val nFrame : Int = 2 // Number of frame (ex : 2)
val inputFrame1 : InputStream = FileInputStream("frame1.png") // Input stream of your frame 1 (ex : a FileInputStream)
val inputFrame2 : InputStream = FileInputStream("frame2.png") // Input stream of your frame 2 (ex : a FileInputStream)
2018-10-23 14:55:49 +00:00
2020-04-20 15:20:35 +00:00
val encoder = ApngEncoder(output, maxWidth, maxHeight, nFrame)
2018-10-23 14:55:49 +00:00
2020-04-20 15:20:35 +00:00
encoder.writeFrame(inputFrame1)
inputFrame1.close()
2018-10-23 14:55:49 +00:00
2020-04-20 15:20:35 +00:00
encoder.writeFrame(inputFrame2, delay=500f) // With delay ! Default is 1000ms
inputFrame2.close()
2018-10-23 14:55:49 +00:00
2020-04-20 15:20:35 +00:00
encoder.writeEnd()
output.close()
2018-10-23 14:55:49 +00:00
```
2018-10-24 11:28:13 +00:00
2020-04-20 15:20:35 +00:00
# How to install :
## Via jitpack [![](https://jitpack.io/v/oupson/Kapng-Android.svg)](https://jitpack.io/#oupson/Kapng-Android)
2018-10-24 11:28:13 +00:00
```gradle
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
2020-04-20 15:20:35 +00:00
implementation 'com.github.oupson:Kapng-Android:1.0.10-beta2'
2018-10-24 11:28:13 +00:00
}
```
2020-04-20 15:20:35 +00:00
## Or put the aar file in /libs/ and verify that you have :
2018-10-24 11:28:13 +00:00
```gradle
dependencies {
implementation fileTree(include: ['*.aar'], dir: 'libs')
}