【问题标题】:How to use high resolution(4k) image in android app如何在 Android 应用程序中使用高分辨率(4k)图像
【发布时间】:2021-12-11 02:37:32
【问题描述】:

我从 API 获取高分辨率图像并将它们显示在我的应用程序上。我不熟悉处理高分辨率图像或一般图像,所以当我看到我的应用程序上的图像模糊时,我感到很惊讶。

1)如何才能以高分辨率显示

2)可以做些什么来减轻分辨率的损失?

我正在使用 Coil 库将图像加载到 Android 上可组合的图像中。

在 google 像素 3a 上进行测试。

以下是显示图像的应用与显示另一图像的浏览器之间的区别示例:

我的可组合看起来像这样:

Image(
      painter = rememberImagePainter(
                    imageUrl,
                    builder = { allowHardware(false) }
                ),
      contentDescription = "",
      modifier = Modifier
                    .fillMaxWidth()
                    .aspectRatio(1f),
      contentScale = ContentScale.Fit,
     )

更新:

  1. 我已经尝试使用 ImageView 而不是可组合的,但我仍然 得到相同的结果。

【问题讨论】:

  • 尝试将图像(使用 Coil 或 Glide 或其他)加载到 ImageView,以帮助确定它是否是 Coil 的 Compose UI 支持是您的困难的根源。
  • 我试过了,但似乎没有什么不同......不过我很欣赏这个想法

标签: android android-jetpack-compose android-image coil


【解决方案1】:

builder 中,将图像大小(以像素为单位)强制为您喜欢的大小。

Image(
    painter = rememberImagePainter(
        imageUrl,
        builder = {
            allowHardware(false)
            size(image.width, image.height)
        }
    ),
    contentDescription = "",
    modifier = Modifier
        .fillMaxWidth()
        .aspectRatio(1f),
    contentScale = ContentScale.Fit,
)

请注意,虽然在指定非常高分辨率时会导致崩溃RuntimeException: Canvas: trying to draw too large bitmap

【讨论】:

  • 它除了缩放图像并没有做太多事情,质量保持不变
猜你喜欢
  • 1970-01-01
  • 2021-08-17
  • 1970-01-01
  • 1970-01-01
  • 2014-11-20
  • 1970-01-01
  • 1970-01-01
  • 2012-01-29
  • 2018-08-19
相关资源
最近更新 更多