gpt4 book ai didi

java - Android - 从 URL 获取图像而不保存到存储

转载 作者:行者123 更新时间:2023-11-29 23:55:22 25 4
gpt4 key购买 nike

我从服务器获取图像,我想在我的适配器中显示它。

即使我将 URL 与 Glide 一起使用,或者如果我使用转换 URL->BITMAP->URI,图像保存在图库中。如何在不保存的情况下显示它?或者我如何将它保存为 nomedia,然后将它与 Glide/Picasso 一起使用?

public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}

最佳答案

这将从服务器加载图像,它不会出现在厨房中。

Glide.with(context)
.load(IMAGE_URL)
.into(imageView);

关于缓存,我们可以在 Glide 的文档中找到:

The default strategy, AUTOMATIC, tries to use the optimal strategy for local and remote images. AUTOMATIC will store only the unmodified data backing your load when you’re loading remote data (like from URLs) because downloading remote data is expensive compared to resizing data already on disk. For local data AUTOMATIC will store the transformed thumbnail only because retrieving the original data is cheap if you need to generate a second thumbnail size or type.

无论您是否使用缓存,图像都不会在画廊中可见。

关于java - Android - 从 URL 获取图像而不保存到存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50436871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com