GlideWebpDecoder icon indicating copy to clipboard operation
GlideWebpDecoder copied to clipboard

how can i get all bitmap frame from animate webp

Open wujinsheng-ola opened this issue 1 year ago • 1 comments

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

wujinsheng-ola avatar Jan 18 '24 03:01 wujinsheng-ola

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

zjupure avatar Jan 29 '24 14:01 zjupure