使用Glide或coil来显示和缓存生成的位图
我正在尝试优化我的recyclerview,我正在加载从函数生成的pdf缩略图,我设法从返回我的函数显示这些位图,但无法将它们保存在Glide缓存中。每次都会重新生成一个新的,我使用下面的代码片段实现了这个结果。目标是从缓存中加载缩略图(如果已存在),否则生成缩略图。我也听说过 Glide 的签名,但是当我添加这个参数时,我得到了一个错误...我还听说过线圈库,它似乎也提供了这种功能。 有人知道该怎么做吗?
谢谢
val bitmapPdf: Bitmap = BitmapFactory.decodeResource(context.resources,R.drawable.ic_pdf)
Glide.with(context).asBitmap().load(bitmapPdf).into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
}
override fun onResourceReady(
resource: Bitmap,
transition: com.bumptech.glide.request.transition.Transition<in Bitmap>?
) {
val bitmapPdf = pdfToBitmap(currentFile) //My bitmap generator
holder.file_img.setImageBitmap(bitmapPdf)
}
})
I'm trying to optimize my recyclerview, I'm loading in pdf thumbnails generated from a function, I manage to display these bitmaps from a function which return me one’s but impossible to save them in the Glide cache. A new one is regenerated each time, I achieved this result using the piece of code bellow. The goal is to load the thumbnail from the cache if it already exists, otherwise generate it. I heard about signatures also with Glide but when I add this parameter I get an error... Also I heard about coil library which seems to offers this kind of features too.
Someone know how to do it?
Thank you
val bitmapPdf: Bitmap = BitmapFactory.decodeResource(context.resources,R.drawable.ic_pdf)
Glide.with(context).asBitmap().load(bitmapPdf).into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
}
override fun onResourceReady(
resource: Bitmap,
transition: com.bumptech.glide.request.transition.Transition<in Bitmap>?
) {
val bitmapPdf = pdfToBitmap(currentFile) //My bitmap generator
holder.file_img.setImageBitmap(bitmapPdf)
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论