简体   繁体   English

如何从数据库中的 URL 加载图像

[英]How to load image from URL that is in database

How can I load an image using a URL that is saved in a database and display it in a Recycler View in an Image View如何使用保存在数据库中的 URL 加载图像并将其显示在图像视图的 Recycler 视图中

I have a database that displays data as an output in my app but I cant figure out how to make the URL for an image in the database load as an image.我有一个数据库,可以在我的应用程序中将数据显示为输出,但我不知道如何将数据库中图像的 URL 作为图像加载。

you can load an image from URL by using Glide:您可以使用 Glide 从 URL 加载图像:

Import dependency导入依赖

implementation 'com.github.bumptech.glide:glide:4.11.0'实施 'com.github.bumptech.glide:glide:4.11.0'

        Glide
        .with(context)
        .load("URL placed here")
        .centerCrop()
        .placeholder(R.drawable.placeholder)
        .into(imageview)

There are multiple options available to load an image from URL.有多个选项可用于从 URL 加载图像。

You can use Picasso like this:你可以像这样使用毕加索

Picasso.get().load("your_url").into(imageView);

Also you can use Glide (Faster than Picasso)您也可以使用Glide (比毕加索更快)

Glide.with(this).load("your_url").into(imageView);

Or you can convert your URL to Bitmap and then set it into ImageView without using any library.或者您可以将您的 URL 转换为位图,然后将其设置为 ImageView 而无需使用任何库。 See this for this approach: How to get bitmap from a url in android请参阅此方法:如何从 android 中的 url 获取位图

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

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