Glide with Setter 方法 url 图片来源

Glide with Setter method url image source

我想像下面那样设置对象中图像属性的值 class 但使用 Glide

try {
InputStream stream = new URL("my url").openStream();
Bitmap pictureBitmap = BitmapFactory.decodeStream(stream);
"my model class".setImageBitmap(pictureBitmap);
} catch (IOException e) {
            e.printStackTrace();;
        }

我想这就是您使用 Glide 作为位图从 url 源获取图像的方式

Glide
     .with(getContext())
     .load("my url")
     .asBitmap()....

您可以使用 SimpleTarget 作为 into 方法的参数。它将加载您的位图,您可以在图像准备好后将其放入图像模型中。

 Glide
.with(getApplicationContext())
.load(IMAGE_URL)
.asBitmap()
.into(new SimpleTarget<Bitmap>(100,100) {
    @Override
    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
        YourModelClass.setImageBitmap(resource);
    }
});