The library is a powerful and versatile tool for working with animated WebP images. It provides the functionality to encode and decode animated WebP files, allowing developers to create and manipulate animated WebP images with ease.
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
gradle maven sbt leiningen Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.KishorJena:Webp_Transcoder:1.1'
}
For maven: Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.KishorJena</groupId>
<artifactId>Webp_Transcoder</artifactId>
<version>Tag</version>
</dependency>
- you can use this to apply transfromations or animate.
- add frames to AnimationDrawable and start the animation
- create tools
Decoder:
WebpAnimatedDecoder deocder = new WebpAnimatedDecoder(new File(inFile));
List<ProcessedFrames> processedFrames = deocder.decode();
List<Bitmap> bitmaps = new ArrayList<>();
for(int i = 0; i < processedFrames.size()-1; i++){
ProcessedFrames processedFrame = processedFrames.get(i);
Bitmap bitmap = processedFrame.bitmap;
bitmaps.add(bitmap);
}
encodeFrames(outFile, bitmaps);Encoder:
WebpBitmapEncoder encoder = new WebpBitmapEncoder(new File(outFile));
encoder.setLoops(0);
for(int i=0; i<frame.size()-1; i++){
encoder.setDuration(80);
encoder.writeFrame(frame.get(i),80);
}
encoder.close();You should use Thread or AsynTask to prevent UI freezing.
new Thread(new Runnable() {
@Override
public void run() {
// Do long running task here
// (opitional) update UI on main thread here
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText("Task Complete");
}
});
}
}).start();Make sure to import the necessary classes and adjust the code based on your specific requirements and class/package names.
import com.n4no.webpencoder.webp.codec.WebpAnimatedDecoder;
import com.n4no.webpencoder.webp.codec.WebpBitmapEncoder;
import com.n4no.webpencoder.webp.utils.Logs;
import com.n4no.webpencoder.webp.webpData.AnimationData;
import com.n4no.webpencoder.webp.webpData.ProcessedFrames;Tip: If disposal is false then previous frame won't get removed. blending should be true for 'No Blending'