糟糕的ImageView位图质量?

7
我有一个启动画面,其中ImageView扮演背景的角色。无论我是否允许我的位图缩放(我这样做了),图像质量都很差。我认为它正在降低颜色深度。我已经在SO上查找过了,一个建议是将我的图像放置在raw而不是drawable中,但也没有帮助。这里是屏幕截图:

enter image description here

到底发生了什么,我该如何解决呢?
编辑:我没有通过程序应用此位图,因此没有相关的Java代码。这里是此活动的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayoutSplash"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawingCacheQuality="high"
    android:orientation="vertical"
    android:padding="@dimen/splash_padding"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    tools:context=".SplashActivity" >

    <ImageView
        android:id="@+id/ImageViewBg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/logo_description"
        android:scaleType="centerCrop"
        android:src="@drawable/splash_bg_register" />

    <ImageView
        android:id="@+id/ImageViewLogo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/logo_description"
        android:maxHeight="@dimen/logo_maxheight"
        android:maxWidth="@dimen/logo_maxwidth"
        android:layout_centerVertical="true"
        android:src="@drawable/logo" />

    <TextView
        android:id="@+id/TextViewCopyright"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/copyright"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/white_50"
        android:textSize="@dimen/copyright_size" />

</RelativeLayout>

编辑: 我已经尝试了建议中的getWindow().setFormat(PixelFormat.RGBA_8888);,这使差异可见但是色带依然存在。这个是我用作背景的图片。


7
请贴上您的代码。 - Viswanath Lekshmanan
图片的尺寸是多少? - Viswanath Lekshmanan
将android:scaleType设置为matrix - Numair
不,那样不能正确地缩放图像。@Arju,它的高度是1000像素,宽度是800像素。 - Michael Zimmerman
8个回答

8

当图像的宽高比被扭曲时,往往会出现带状失真。

您可以尝试以下任意一种方法:

  1. Make your image .9.png. In that case, it will automatically fix any stretches and take care of banding.

  2. Apply superficial dithering to your image which might prevent any unusual banding.

    <bitmap
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/b1"
        android:tileMode="repeat"
        android:dither="true" />
    

2

我更新了问题,链接到我用作背景的图像副本。它是1000x800像素。我正在Galaxy S Blaze设备上进行测试。我使用一个<bitmap> XML资源引用splash_bg.png。它被缩放以适应目标设备屏幕的高度。宽度被裁剪。 - Michael Zimmerman
1
不需要创建位图XML。只需设置图像和scaleType centerCrop即可。对于Galaxy Blaze,请尝试使用分辨率为480x800的图像副本并将其放入drawable-normal-hdpi文件夹中。 - Yaroslav Mytkalyk

2

您需要设置窗口颜色格式。在您的活动中添加以下内容:

getWindow().setFormat(PixelFormat.RGBA_8888);

这在某种程度上起作用了。我能看到一些明显的差别,但仍然能看到相同的色带伪影。接下来应该尝试什么? - Michael Zimmerman

1
我猜图片的尺寸比显示图片的区域小。因此,可能会对图像进行缩放并失去质量。
What you can try is:

1. Either put the image of similar dimension 
2. use 9 patch image ( good idea )

1
你需要将图像调整为不同的大小,并将它们放置在res/目录下相应的drawable文件夹中。

0

只需将图像设置为背景图像即可轻松调整。以下是示例代码

   <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/your_image"
    />

0

尝试使用抗锯齿可能会解决你的问题。

使用以下xml创建位图可绘制对象。

<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background"
    android:antialias="true"
    android:dither="true"  />

0
你正在做的是在xml中设置图像,这更取决于该图像分辨率所支持的内容。
对于多个设备的每个支持密度,有许多文件夹,将您的图像放在某些dpi的适当文件夹中。
请参考此链接http://developer.android.com/guide/practices/screens_support.html 查看相同应用程序图标在不同文件夹中的行为差异。
例如,没有支持不同密度的应用程序,在低、中和高密度屏幕上显示。

Example application without support for different densities, as shown on low, medium, and high density screens.

enter image description here

示例应用程序具有对不同密度的良好支持(它是密度无关的),如低、中和高密度屏幕所示。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接