【问题标题】:Why android lose image quality when displaying a png file?为什么android在显示png文件时会丢失图像质量?
【发布时间】:2012-10-30 11:10:23
【问题描述】:

我想在 android 上显示 png 图像。这是图片文件:

右端比左端暗一点。

但是在android应用程序上图像质量丢失(使用ImageView):

请注意红框内的部分。颜色变化不是很顺畅。

但是如果我使用我的安卓手机的浏览器,它可以很好地播放(所以不是手机屏幕的原因):

这是我的安卓代码,非常简单:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:background="@drawable/hhh"/>
</LinearLayout>

hhh 是我在此处发布的第一张图片,位于res/drawable 下。

我在我的安卓手机(安卓2.3.6)和安卓模拟器(安卓2.2/2.3/4.0)上测试,都显示不好。但它在我的 android pad(android 4.0.3) 上玩得很好。

有什么问题,如何解决?

【问题讨论】:

标签: android image


【解决方案1】:

res/drawable 中的图像被压缩。 This is supposed to be lossless,但我过去听说过类似的问题。

把它移到res/raw,试试看。

【讨论】:

  • 我刚试过res/raw,但不走运。我把图片移到res/raw,把代码改成&lt;ImageView ... android:background="@raw/hhh" /&gt;,显示不好。
  • 你遇到的问题是条带,你试过抖动吗?这有一些选项/解决方法stackoverflow.com/questions/4769885/…
【解决方案2】:

尝试将以下内容添加到您的 Activity 中,看看是否有帮助。

@Override
public void onAttachedToWindow() {
   super.onAttachedToWindow();
   Window window = getWindow();
   //eliminates color banding
   window.setFormat(PixelFormat.RGBA_8888);
}

【讨论】:

    【解决方案3】:

    这个问题是众所周知的梯度带问题,我有这个问题并通过添加噪声解决,例如http://planetphotoshop.com/say-goodbye-to-gradient-banding.html

    【讨论】:

      猜你喜欢
      • 2012-05-27
      • 2016-11-27
      • 2015-12-06
      • 2013-09-13
      • 2014-12-07
      • 2016-05-18
      • 2011-07-02
      • 2011-04-18
      • 2015-03-20
      相关资源
      最近更新 更多