Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/penfeizhou/apng4android
Android animation support for APNG & Animated WebP & Gif & Animated AVIF, High performance
https://github.com/penfeizhou/apng4android
android animatedavif animatedwebp animation apng avif awebp glide webp
Last synced: 16 days ago
JSON representation
Android animation support for APNG & Animated WebP & Gif & Animated AVIF, High performance
- Host: GitHub
- URL: https://github.com/penfeizhou/apng4android
- Owner: penfeizhou
- License: apache-2.0
- Created: 2019-03-31T10:55:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-03T06:43:46.000Z (4 months ago)
- Last Synced: 2024-10-05T09:38:24.725Z (about 1 month ago)
- Topics: android, animatedavif, animatedwebp, animation, apng, avif, awebp, glide, webp
- Language: Java
- Homepage:
- Size: 35.4 MB
- Stars: 574
- Watchers: 15
- Forks: 75
- Open Issues: 9
-
Metadata Files:
- Readme: README-zh_CN.md
- License: LICENSE
Awesome Lists containing this project
README
# Android 动画播放库
* 支持常用动画格式APNG、Animated WebP、Gif、AVIF
* 解码实现高效,占用内存极低
* 支持按Resource、Assets、File等多种方式读取
* 提供Glide插件,可使用Glide直接加载
* 支持动画播放过程控制
* 支持静图展示## [版本记录](https://github.com/penfeizhou/APNG4Android/releases)
## 使用说明
### 在build.gradle添加依赖
```gradle
repositories {
mavenCentral()
}
```
#### Animated WebP
```gradle
dependencies {
implementation 'com.github.penfeizhou.android.animation:awebp:${VERSION}'
}
```
#### APNG
```gradle
dependencies {
implementation 'com.github.penfeizhou.android.animation:apng:${VERSION}'
}
```
#### Gif
```gradle
dependencies {
implementation 'com.github.penfeizhou.android.animation:gif:${VERSION}'
}
```
#### AVIF
```gradle
dependencies {
implementation 'com.github.penfeizhou.android.animation:avif:${VERSION}'
}
```
### `使用前请注意!`
`不要将APNG资源放置到drawable或者mipmap目录下!` 在Android app release构建过程中, aapt工具会压缩修改APNG资源的帧信息, 会导致播放不正常. 因此请将APNG资源放置到工程内的`raw`或者`assets`目录内.### 使用
```java
// 从asset file中加载
AssetStreamLoader assetLoader = new AssetStreamLoader(context, "wheel.png");// 从resource中加载
ResourceStreamLoader resourceLoader = new ResourceStreamLoader(context, R.drawable.sample);// 从file中加载
FileStreamLoader fileLoader = new FileStreamLoader("/sdcard/Pictures/1.webp");// 创建APNG Drawable
APNGDrawable apngDrawable = new APNGDrawable(assetLoader);//创建 Animated webp drawable
WebPDrawable webpDrawable = new WebPDrawable(assetLoader);//自动播放
imageView.setImageDrawable(apngDrawable);//可覆盖动画中设置的播放次数
apngDrawable.setLoopLimit(10);// 实现Animatable2Compat接口
drawable.registerAnimationCallback(new Animatable2Compat.AnimationCallback() {
@Override
public void onAnimationStart(Drawable drawable) {
super.onAnimationStart(drawable);
}
});
```
## Glide插件### build.gradle中添加依赖
```gradle
repositories {
...
mavenCentral()
}
dependencies {
implementation 'com.github.penfeizhou.android.animation:glide-plugin:${VERSION}'
}
```
### 使用Glide加载图片```java
Glide.with(imageView).load("https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png").into(imageView);
Glide.with(imageView).load("https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp").into(imageView);
```