我可以使用Glide同步加载图像吗? [英] Can I load images synchronously with Glide?

查看:911
本文介绍了我可以使用Glide同步加载图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道从设备存储中同步加载位图不是很实际,但是我确实必须这样做.我还没有想办法做到这一点.

I know it isn't very practical to load bitmaps from the device storage synchronously, but I really have to do it. I haven't figured out any way to do this.

推荐答案

可以,并且在滑行文档.

例如,如果您需要同步检索位图,则可以执行以下操作:

For example if you need to retrive the Bitmap synchronously you can do:

Glide V3:

Bitmap myBitmap = Glide.with(applicationContext)
.load(yourUrl)
.asBitmap()
.into(500, 500)
.get()

Glide v4:

FutureTarget<Bitmap> futureBitmap = Glide.with(applicationContext)
                           .asBitmap()
                           .load(yourURL)) 
                           .submit();
Bitmap myBitmap = futureBitmap.get();

注意:此代码需要在后台运行,否则应用程序将崩溃.

Note: This code need to be run in the background or the app will crash.

这篇关于我可以使用Glide同步加载图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆