【问题标题】:What is the best approach to send and receive the big image files in a Firebase/Android chat app在 Firebase/Android 聊天应用程序中发送和接收大图像文件的最佳方法是什么
【发布时间】:2018-08-21 02:06:02
【问题描述】:

我正在开发一个使用 Firebase 实时数据库和存储的聊天应用。

目前我使用这种方法来发送和接收图像:

  • 单击发送按钮时:图库的意图 >> 将图像上传到 Firebase 存储 >> 将图像 URL 存储在 Firebase 数据库中的消息子项中。
  • 在适配器中,当消息中的子类型设置为“图像”时,我使用 Picasso 及其离线功能将图像检索到 ImageView。

问题在于高质量图像超过 1 MB。一旦它们被发送,应用程序在滚动聊天时会变得非常慢,然后一些图像会从 ImageView 中消失。

有没有办法让图像检索更顺畅、更快?

【问题讨论】:

标签: android firebase firebase-storage picasso offline-caching


【解决方案1】:

如果您使用的是Glide,那么您可以调整图像的大小和缩放比例。假设您使用 Glide 4.x,请使用以下选项之一:

首先是使用override(x, y) 方法将图像调整为特定尺寸:

GlideApp  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .override(600, 200)
    .into(imageViewResize);

第二种方法是将override(x, y)centerCrop() 一起使用。这是一种裁剪技术,可缩放图像以填充请求的边界,然后裁剪多余的区域。

GlideApp  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .override(600, 200)
    .centerCrop()
    .into(imageViewResizeCenterCrop);

第三种方法是使用fitCenter(),这是一种裁剪技术,可以缩放图像,使两个尺寸都等于或小于ImageView 的请求边界。图片将完全显示,但可能不会填满整个ImageView

GlideApp  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .override(600, 200)
    .fitCenter() 
    .into(imageViewResizeFitCenter);

【讨论】:

  • 我可以在不裁剪的情况下做到这一点吗?例如改变质量?
  • Glide 已经使用了设置为RGB_565 的默认位图格式。您可以按照here 的说明将其增加到原始格式,但要减少,您的图像看起来会更糟。
猜你喜欢
  • 1970-01-01
  • 2023-03-26
  • 2020-06-20
  • 1970-01-01
  • 1970-01-01
  • 2015-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多