从 firebase 加载图像很慢
Loading images from firebase is slow
每当我登录我的应用程序时。图片加载缓慢。加载通常需要很多时间。
我在我的应用程序中使用 Glide
作为图像加载库。
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
上面的代码用于将图像加载到我的 UI 上的 ImageView
,因为您可以看到加载完整图像需要很多时间。
如何才能更快地从 Firebase 加载图像
存储空间?
当您的应用以 Glide.preload() 开头或使用内置的 Glide 缓存时,您可以预加载图像
考虑修改磁盘缓存类型。
.skipMemoryCache( false ) 明确告诉 Glide 不要跳过内存缓存从而更快 loading.Also,你可以使用 .diskCacheStrategy() 方法改变 Glide 的磁盘缓存行为。
DiskCacheStrategy.NONE 什么都不缓存
DiskCacheStrategy.SOURCE 仅缓存原始全分辨率
图片。在我们上面的示例中,这将是 1000x1000 像素的
DiskCacheStrategy.RESULT 只缓存最终图像,减少后
分辨率(以及可能的转换)(默认行为)
DiskCacheStrategy.ALL 缓存图像的所有版本
借助 Krish(在 Whosebug 上)。他建议我更改此代码
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
到此代码。它可以完美地使用以下代码。
Glide.with(getContext())
.load(message.getPhotoUrl())
.asBitmap()
.centerCrop()
.into(new SimpleTarget < Bitmap > () {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation << ? super Bitmap > glideAnimation) {
photoImageView.setImageBitmap(resource);
}
});
除了从 url 加载之外,您还可以尝试使用内置的 FIREBASE 图像加载器
StorageReference storageReference = //make a Reference to your Image
Glide.with(context)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(ImageView);
您也可以考虑使用 Picasso,恕我直言,它的加载速度比 Glide 快。
每当我登录我的应用程序时。图片加载缓慢。加载通常需要很多时间。
我在我的应用程序中使用 Glide
作为图像加载库。
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
上面的代码用于将图像加载到我的 UI 上的 ImageView
,因为您可以看到加载完整图像需要很多时间。
如何才能更快地从 Firebase 加载图像 存储空间?
当您的应用以 Glide.preload() 开头或使用内置的 Glide 缓存时,您可以预加载图像
考虑修改磁盘缓存类型。
.skipMemoryCache( false ) 明确告诉 Glide 不要跳过内存缓存从而更快 loading.Also,你可以使用 .diskCacheStrategy() 方法改变 Glide 的磁盘缓存行为。
DiskCacheStrategy.NONE 什么都不缓存
DiskCacheStrategy.SOURCE 仅缓存原始全分辨率 图片。在我们上面的示例中,这将是 1000x1000 像素的
DiskCacheStrategy.RESULT 只缓存最终图像,减少后 分辨率(以及可能的转换)(默认行为)
DiskCacheStrategy.ALL 缓存图像的所有版本
借助 Krish(在 Whosebug 上)。他建议我更改此代码
Glide.with(photoImageView.getContext())
.load(message.getPhotoUrl())
.into(photoImageView);
到此代码。它可以完美地使用以下代码。
Glide.with(getContext())
.load(message.getPhotoUrl())
.asBitmap()
.centerCrop()
.into(new SimpleTarget < Bitmap > () {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation << ? super Bitmap > glideAnimation) {
photoImageView.setImageBitmap(resource);
}
});
除了从 url 加载之外,您还可以尝试使用内置的 FIREBASE 图像加载器
StorageReference storageReference = //make a Reference to your Image
Glide.with(context)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(ImageView);
您也可以考虑使用 Picasso,恕我直言,它的加载速度比 Glide 快。