2013-04-04 44 views
6

我有一个启动画面,其中有一个ImageView作为背景的一部分。无论我是否允许缩放(我所做的)位图,图像质量都很糟糕。我认为这是减少颜色深度。我已经环顾过了,一个建议是将我的图像放在raw而不是drawable,但这也没有帮助。下面是截图:可怕的ImageView位图质量?

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);的建议这让一个明显的区别,但条纹仍然存在。 This是我用作背景的图像。

+7

发布您的代码。 – 2013-04-04 11:30:17

+0

对不起。 – 2013-04-04 11:35:02

+0

图像的大小是多少? – 2013-04-04 11:47:32

回答

8

当图像的宽高比受到干扰时,出现大部分条纹。

你可以尝试以下的任何一个:

  1. ,使图像.9.png。在这种情况下,它将自动修复任何延伸并照顾绑扎。

  2. 将肤浅的抖动应用到您的图像上,这可能会阻止任何不寻常的条带。

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

你的图像的尺寸是多少?什么是设备? 我怀疑图像大小与显示大小不匹配,并且它位于错误的资源可绘制文件夹中。图像看起来相当规模。这些文章应该可以帮助您选择不同屏幕的图像分辨率和资源文件夹。

http://developer.android.com/guide/practices/screens_support.html

http://developer.android.com/training/multiscreen/index.html

+0

我更新了问题以链接到我用作背景的图像的副本。它是1000x800px。我正在测试Galaxy S Blaze设备。我正在使用引用'splash_bg.png'的''XML资源。它被缩放以适应目标设备屏幕的高度。宽度被裁剪。 – 2013-04-04 18:38:31

+1

不需要创建位图xml。只需设置图像和scaleType centerCrop是正确的。对于Galaxy Blaze,请尝试制作分辨率为480x800的图像副本,并将其放入drawable-normal-hdpi文件夹中。 – 2013-04-05 07:41:34

2

你必须设置窗口的颜色格式。在你的活动中加入类似这样的东西:

getWindow().setFormat(PixelFormat.RGBA_8888); 
+0

这在一定程度上有效。我可以看到一些明显的差异,但我仍然看到相同的带状伪影。想知道下一步该做什么? – 2013-04-04 18:31:22

0

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

用下面的xml创建一个可绘制的位图。

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

我想图像的尺寸大于在其上显示图像的面积小。所以,可能是图像正在放大和失去质量。

What you can try is: 

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

您需要调整您的图像转换成不同的尺寸,并把那些为各自绘制的文件夹下res/

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

支持不同密度(不受密度影响)的示例应用,如低,中,高密度屏幕所示。

0

只是通过使图像成为背景图像来调整它。这里是一个示例代码

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