这个问题可能看起来非常基本,但我正在考虑在我的 RecyclerView 中使用 Glide,其中我有超过 1,000 个项目。当我打开这个列表时 - Glide 开始下载所有图像还是只下载我面前实际存在的图像 - 那么如果我从 A 快速滚动到 E,它也会下载 B、C 和 D 的图像吗?
我知道这是一个非常基本的问题。我尝试找到多种解决方案,但我无法理解它们。
我想要的是
将图像上传到服务器,作为回报,我得到了 URL,但问题是在使用此 URL 设置图像时,设置了旧图像。发生这种情况是因为滑翔正在获取旧缓存而不是更新缓存。
怎么解决这个问题。
Glide.clear(profilePic);
Glide.with(getApplicationContext())
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(true)
.transform(new CircleTransform(MainProfile.this))
.into(profilePic);
Run Code Online (Sandbox Code Playgroud)
目前,图片已更改,但是当我单击后退按钮并返回此活动时,它会加载旧图像。像这样从缓存加载图像。
//setting up the profile pic
Glide.with(getApplicationContext())
.load(userProfilePicUrl)
.asBitmap()
.centerCrop()
.into(new BitmapImageViewTarget(profilePic) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(MainProfile.this.getResources(), resource);
circularBitmapDrawable.setCircular(true);
profilePic.setImageDrawable(circularBitmapDrawable);
}
});
Run Code Online (Sandbox Code Playgroud)
问题是,当我回到此活动时,它显示旧图片而不是新图片。
我使用 glide 从视频 url 获取帧,但使用 glide 获取帧,下载整个视频,这需要时间。
RequestOptions myOptions = new RequestOptions()
.fitCenter()
.centerCrop().circleCrop()
.placeholder(R.drawable.loading_circle);
Glide.with(context)
.asBitmap()
.apply(myOptions)
.load(Link)
.into(image);
Run Code Online (Sandbox Code Playgroud)
如何获取视频的最后一帧?
我尝试了几种不同的方法,但图像视图仍然只显示灰色方块。我正在 API 17 上进行测试。
以下是我尝试过但未成功的选项:
将 XML 中的 ImageView 配置为:
固定宽度和高度;宽度和高度为wrap_content;宽度为match_parent,高度为wrap_content
- android:scaleType为“fitXY”和“centerCrop”
- android:将ViewBounds调整为true | 错误的;
尝试过的图像加载方法:
binding.captcha.setImageBitmap (BitmapFactory.decodeFile (imgFile2.getAbsolutePath ()));
Run Code Online (Sandbox Code Playgroud)
还尝试了这个答案/sf/answers/2508156031/
尝试过滑行:
Glide.with(this)
.load (Uri.fromFile (imgFile2))
.skipMemoryCache (true)
.diskCacheStrategy (DiskCacheStrategy.NONE)
.override (150, 150)
.centerCrop ()
.into (binding.captcha);
Run Code Online (Sandbox Code Playgroud)
下面的选项是唯一显示图像(在背景中)的选项,但是我想知道可能会发生什么来阻止我使用默认方法显示图像......
Drawable drawableImage = new BitmapDrawable(BitmapFactory.decodeFile(imgFile2.getAbsolutePath()));
binding.captcha.setBackgroundDrawable(drawableImage);
Run Code Online (Sandbox Code Playgroud)
当前的 XML:
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:id="@+id/captcha"/>
Run Code Online (Sandbox Code Playgroud) 我想通过 Glide 通过将图像从 URL 加载到图像视图来播放视频。,我尝试通过使用以下代码调用相同的 URL 来刷新图像:
Glide.with(context)
.load(imageUrl)
.apply(RequestOptions.skipMemoryCacheOf(true))
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
如何在循环中做到这一点???我总是遇到例外
我正在尝试通过滑行找出 gif 的结尾。
这是我在网上找到的代码:
Glide.with(thisActivity).asGif().load(R.raw.logo_gif_motion_low).listener(object : RequestListener<GifDrawable> {
override fun onLoadFailed(p0: GlideException?, p1: Any?, p2: Target<GifDrawable>, p3: Boolean): Boolean {
}
override fun onResourceReady(p0: GifDrawable?, p1: Any?, p2: Target<GifDrawable>, p3: DataSource?, p4: Boolean): Boolean {
return false
}
}).into(splashscreen);
Run Code Online (Sandbox Code Playgroud)
问题是,它不接受GifDrawable的目标。
错误说:
我在 GridView 中显示了来自服务器的大约 50 多张带有 url 的图像,当加载图像花费太多时间时,该图像具有图像(120*120)。平均原始图像大小约为 50-200 KB
滑行代码:
在 GridViewAdapter 中
RequestOptions reqOpt = RequestOptions.fitCenterTransform().transform(new RoundedCorners(5));
...
GlideApp
.with(context)
.load(item.getUrl())
.apply(reqOpt)
.placeholder(R.drawable.place_holder)
.into(holder.ivThumb);
Run Code Online (Sandbox Code Playgroud)
在 Gradle 中
...
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
...
Run Code Online (Sandbox Code Playgroud) 我为每个集群项目使用动态图标,所以我有特殊的图标 url 和从 url 加载标记图标。我使用以下代码:
override fun onBeforeClusterItemRendered(item: T, markerOptions: MarkerOptions?) {
super.onBeforeClusterItemRendered(item, markerOptions)
try {
var url = URL("https://cdn3.iconfinder.com/data/icons/places/100/map_pin_big_1-128.png")
Glide.with(context)
.asBitmap()
.load(url)
.into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
}
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
markerOptions?.icon(BitmapDescriptorFactory.fromBitmap(resource))
}
})
} catch (ex: Exception) {
Log.e("map", ex.toString())
}
Run Code Online (Sandbox Code Playgroud)
}
在我的情况下,某些图标仍然默认,放大后有时会更改缩小图标。问题是此代码不适用于每个集群项,缩放更改的集群图标也更改后,它可能会呈现我的自定义图标并可能使用默认值。
android google-maps markerclusterer android-maps-utils android-glide
我正在开发一个应用程序,需要从其网址加载多个图像。我将所有图像保存在 firebase 存储中。我目前正在使用压缩器来减小尺寸。
newImageFile=new File(uri1.getPath());
try {
compressedImageFile = new Compressor(ProductAdd.this)
.compressToBitmap(newImageFile);
} catch (IOException e) {
e.printStackTrace();
}
baos = new ByteArrayOutputStream();
compressedImageFile.compress(Bitmap.CompressFormat.JPEG, 100, baos);
thumbData1 = baos.toByteArray();
Run Code Online (Sandbox Code Playgroud)
我使用 Glide 从 url 加载图像
Glide.with(context).load(imgUrl).into(holder.cutImg);
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何方法可以改进以更快地加载图像。也许以特定的格式存储它们。
android ×10
android-glide ×10
imageview ×2
java ×2
caching ×1
firebase ×1
google-maps ×1
image ×1