简体   繁体   English

使用 Glide 从 filesDir() 加载九个补丁

[英]Load nine patch with Glide from filesDir()

I am trying to load a .9.png from filesDir() that I have previously downloaded from a server into a View :我正在尝试将.9.png从我之前从服务器下载的filesDir()加载到View 中

Glide.with(context).asDrawable().load(f.absolutePath).dontTransform().into(object : CustomTarget<Drawable>() {
            override fun onLoadStarted(placeholder: Drawable?) {
                super.onLoadStarted(placeholder)
                Log.v("DRAWABLE_TEST", "onLoadStarted")
            }

            override fun onLoadFailed(errorDrawable: Drawable?) {
                super.onLoadFailed(errorDrawable)
                Log.e("DRAWABLE_TEST", "onLoadFailed")
            }

            override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
                Log.v("DRAWABLE_TEST", "onResourceReady")
                view.background = resource
            }

            override fun onLoadCleared(placeholder: Drawable?) {
            }
        })

But I get only normal drawable that is stretched.但我只能得到拉伸的正常可绘制对象。

Any idea how should I load it?知道我应该如何加载它吗?

Ok, I have managed to do it, but not with Glide:好的,我已经设法做到了,但不是使用 Glide:

val bmp = BitmapFactory.decodeFile(f.absolutePath)
val chunk = bmp.ninePatchChunk
val ninePatchDrawable = NinePatchDrawable(context.resources, bmp, chunk, Rect(), null)

However, before downloading the *.9.png images they should be build in some APK and then uploaded to the server.但是,在下载 *.9.png 图像之前,它们应该在一些 APK 中构建,然后上传到服务器。 Source here来源在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM