【问题标题】:Horrible ImageView bitmap quality?可怕的 ImageView 位图质量?
【发布时间】:2016-01-08 08:58:49
【问题描述】:

我有一个带有ImageView 的初始屏幕,它扮演着背景的角色。无论我是否允许缩放位图(我这样做),图像质量都很糟糕。我认为它会降低颜色深度。我已经环顾四周了,一个建议是将我的图像放在raw 而不是drawable 中,但这也无济于事。这是截图:

这里到底发生了什么,我该如何解决?

编辑:我没有以编程方式应用此位图,因此没有相关的 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 是我用作背景的图片。

【问题讨论】:

  • 发布您的代码。
  • 图片大小是多少?
  • 将 android:scaleType 设置为 matrix
  • 不,这不能正确缩放图像。 @Arju,它高 1000 像素,宽 800 像素。

标签: android android-imageview


【解决方案1】:

条纹主要发生在图像的纵横比受到干扰时。

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

  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

    【讨论】:

    • 我更新了问题以链接到我用作背景的图像的副本。它是 1000x800 像素。我正在 Galaxy S Blaze 设备上进行测试。我正在使用引用splash_bg.png&lt;bitmap&gt; XML 资源。它被缩放以适应目标设备屏幕的高度。宽度被裁剪。
    • 无需创建位图xml。只需设置图像和 scaleType centerCrop 是正确的。对于 Galaxy Blaze,请尝试制作分辨率为 480x800 的图像副本并将其放入 drawable-normal-hdpi 文件夹中。
    【解决方案3】:

    您必须设置窗口颜色格式。在您的活动中输入如下内容:

    getWindow().setFormat(PixelFormat.RGBA_8888);
    

    【讨论】:

    • 这在一定程度上奏效了。我可以看到一些明显的差异,但我仍然看到相同的条带伪影。知道接下来要尝试什么吗?
    【解决方案4】:

    我猜图像的大小小于显示图像的区域。所以,可能是图像正在放大并失去质量。

    What you can try is:
    
    1. Either put the image of similar dimension 
    2. use 9 patch image ( good idea )
    

    【讨论】:

      【解决方案5】:

      您需要将图像调整为不同的大小,并将它们放入res/下的各个可绘制文件夹中

      【讨论】:

        【解决方案6】:

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

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

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

        【讨论】:

          【解决方案7】:

          您正在做的是在 xml 中设置图像,这更多取决于 关于该图像分辨率支持的内容。

          每个支持的多个设备的密度都有多个文件夹,将您的图像放在某个合适的 dpi 文件夹中。

          请参考此链接http://developer.android.com/guide/practices/screens_support.html

          查看相同的应用程序图标在不同文件夹中的表现如何

          不支持不同密度的示例应用程序,如低、中和高密度屏幕所示

          很好地支持不同密度的示例应用程序(它与密度无关),如在低、中和高密度屏幕上所示。

          【讨论】:

            【解决方案8】:

            只需通过将图像设置为背景图像来调整它。这是一个示例代码

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

            【讨论】:

              猜你喜欢
              • 2019-01-30
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-03-29
              • 2013-08-10
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多