简体   繁体   English

为什么android在显示png文件时会丢失图像质量?

[英]Why android lose image quality when displaying a png file?

I want to display a png image on android. 我想在android上显示一个png图像。 This is the image file: 这是图像文件:

在此输入图像描述

The right end is a bit darker than left. 右端比左侧略深。

But the quality of image lost on android application(using ImageView): 但是在Android应用程序上丢失的图像质量(使用ImageView):

在此输入图像描述

Please note part in the red frame. 请注意红框中的部分。 The color is not changing smoothly. 颜色没有平滑变化。

But if I use the browser of my android phone, it plays good(so it's not reason of the phone screen): 但是,如果我使用我的Android手机的浏览器,它播放效果很好(所以这不是手机屏幕的原因):

在此输入图像描述

This is my android code, which is pretty simple: 这是我的android代码,非常简单:

<?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>

where hhh is my first image posted here, which is under res/drawable . hhh是我在这里发布的第一张图片,它位于res/drawable

I test it on my android phone(android 2.3.6) and android simulator(with android 2.2/2.3/4.0), all do not display good. 我在我的Android手机(android 2.3.6)和android模拟器(用android 2.2 / 2.3 / 4.0)上测试它,都显示不好。 But it plays good on my android pad(android 4.0.3). 但它在我的android pad(android 4.0.3)上播放效果很好。

What's the problem, and how to fix it? 问题是什么,以及如何解决?

Images in res/drawable are compressed. res/drawable中的图像被压缩。 This is supposed to be lossless , but I've heard of similar issues in the past. 这应该是无损的 ,但我在过去听说过类似的问题。

Move it into res/raw , and give it a go. 将它移动到res/raw ,然后试一试。

Try adding the following to your Activity and see if it helps. 尝试将以下内容添加到您的Activity ,看看它是否有帮助。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM