Update Readme
This commit is contained in:
parent
a8ad3c4e4d
commit
7657c0e505
61
README.md
61
README.md
|
@ -1,48 +1,65 @@
|
|||
# Kapng-Android
|
||||
An android library to create or display apng
|
||||
### An android library to create or display apng
|
||||
|
||||
Example of apng :
|
||||
# Example of apng :
|
||||
|
||||
![apng-example](https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png)
|
||||
|
||||
How to use this library :
|
||||
# How to use this library :
|
||||
|
||||
To load animated png to an imageView :
|
||||
## To load an animated png to an imageView :
|
||||
```kotlin
|
||||
val imageUrl = "https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png" // image url could be an url, or a file path. You could also load byteArray and file
|
||||
val imageUrl = "https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png"
|
||||
|
||||
val animator = imageView.load(imageUrl)
|
||||
ApngDecoder.decodeApngAsyncInto(context, URL(url), imageView)
|
||||
```
|
||||
|
||||
To create animated png :
|
||||
You can load a file, an uri, a ressource int, an url, or an inputStream.
|
||||
|
||||
## With a callback :
|
||||
```kotlin
|
||||
|
||||
val apng = Apng()
|
||||
|
||||
val file1 = File("image path 1")
|
||||
val file2 = File("image path 2")
|
||||
|
||||
apng.addFrames(BitmapFactory.decodeByteArray(file1.readBytes(), 0, file1.readBytes().size))
|
||||
apng.addFrames(BitmapFactory.decodeByteArray(file2.readBytes(), 0, file2.readBytes().size))
|
||||
|
||||
val apngByteArray = apng.generateAPNGByteArray()
|
||||
File("output file path").writeBytes(apngByteArray)
|
||||
ApngDecoder.decodeApngAsyncInto(this, uri, viewerImageView, callback = object : ApngDecoder.Callback {
|
||||
override fun onSuccess(drawable: Drawable) { println("Success !") }
|
||||
override fun onError(error: Exception) { println("Error : $error") }
|
||||
})
|
||||
```
|
||||
|
||||
How to install :
|
||||
Via jitpack [![](https://jitpack.io/v/oupson/Kapng-Android.svg)](https://jitpack.io/#oupson/Kapng-Android)
|
||||
## 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)
|
||||
|
||||
val encoder = ApngEncoder(output, maxWidth, maxHeight, nFrame)
|
||||
|
||||
encoder.writeFrame(inputFrame1)
|
||||
inputFrame1.close()
|
||||
|
||||
encoder.writeFrame(inputFrame2, delay=500f) // With delay ! Default is 1000ms
|
||||
inputFrame2.close()
|
||||
|
||||
encoder.writeEnd()
|
||||
output.close()
|
||||
```
|
||||
|
||||
# How to install :
|
||||
## Via jitpack [![](https://jitpack.io/v/oupson/Kapng-Android.svg)](https://jitpack.io/#oupson/Kapng-Android)
|
||||
```gradle
|
||||
repositories {
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.oupson:Kapng-Android:1.0.9'
|
||||
implementation 'com.github.oupson:Kapng-Android:1.0.10-beta2'
|
||||
}
|
||||
```
|
||||
|
||||
Or put the aar file in /libs/ and verify that you have :
|
||||
## Or put the aar file in /libs/ and verify that you have :
|
||||
```gradle
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.aar'], dir: 'libs')
|
||||
|
|
Loading…
Reference in New Issue