GlideWebpDecoder
GlideWebpDecoder copied to clipboard
how can i get all bitmap frame from animate webp
i want to get all bitmap frame from animate webp ,then i can convert each bitmap to nine patch drawable ,thus i can implement animate nine patch chat bubble。just like this:
Glide.with(viewBind.tvWebpNinePatch).load(animatedWebpUrl)
.optionalTransform(WebpDrawable::class.java, WebpDrawableTransformation(object : Transformation<Bitmap> {
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
}
override fun transform(context: Context, resource: Resource<Bitmap>, outWidth: Int, outHeight: Int): Resource<Bitmap> {
val frame = resource.get()
val drawable = NinePatchDrawableBuilder(bitmap = frame, resources)
.setHorizontalStretchBean(PatchStretchBean(60, 61))//水平拉伸区域
.setVerticalStretchBean(PatchStretchBean(52, 53))//垂直拉伸区域
.setOriginSize(128, 112)//原始图片大小
.setPadding(Rect(31, 37, 90, 75))//padding区域
.setHorizontalMirror(true)//是否水平镜像,不是必须的
.get9PatchDrawable()
viewBind.tvWebpNinePatch.background = drawable
return resource
}
}))
.into(object : CustomViewTarget<View?, Drawable?>(viewBind.tvWebpNinePatch) {
override fun onLoadFailed(errorDrawable: Drawable?) {
}
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable?>?) {
// getView().background = resource
}
override fun onResourceCleared(placeholder: Drawable?) {}
})
i can not get each frame from transform。 please help me ,thanks very much
It's not support, WebpDrawable manage the frame bitmap and drive it to animate. If you want to animate the nine patch drawable, you might write a custom nine patch drawable to draw webp bitmap into canvas and invalidate it continually