简体   繁体   English

可怕的ImageView位图质量?

[英]Horrible ImageView bitmap quality?

I've got a splash screen with an ImageView playing the part of a background. 我有一个启动画面, ImageView播放背景的一部分。 Regardless of whether or not I allow my bitmap to be scaled (which I do), the image quality is horrible. 无论我是否允许我的位图缩放(我这样做),图像质量都很糟糕。 I think it's reducing the color depth. 我认为这会减少颜色深度。 I've looked around SO already and one suggestion was to place my image in raw instead of drawable but that didn't help either. 我已经环顾四周了,一个建议就是将我的图像放在raw图像而不是drawable但这也无济于事。 Here is a screenshot: 这是一个截图:

在此输入图像描述

What exactly is going on here and how do I fix it? 到底发生了什么,我该如何解决?

EDIT: I didn't apply this bitmap programmatically so there's no relevant Java code. 编辑:我没有以编程方式应用此位图,因此没有相关的Java代码。 Here is the XML code for this activity: 以下是此活动的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>

EDIT: I tried getWindow().setFormat(PixelFormat.RGBA_8888); 编辑:我试过getWindow().setFormat(PixelFormat.RGBA_8888); as suggested which made a visible difference but the banding is still present. 如所建议的那样产生了明显的差异但是条带仍然存在。 This is the image I'm using as the background. 是我用作背景的图像。

Banding occurs mostly when aspect ratio of the image is disturbed. 当图像的纵横比受到干扰时,主要发生条带化。

You could try any one of the following: 您可以尝试以下任何一种方法:

  1. Make your image .9.png . 制作你的形象.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" /> 

What are the dimentions of your image? 你的形象有哪些尺寸? And what is the device? 什么是设备? What I suspect is that image size does not match the size of the display and it is in wrong resource drawable folder. 我怀疑的是图像大小与显示器的大小不匹配,并且它位于错误的资源可绘制文件夹中。 The image looks pretty scaled. 图像看起来相当规模。 These articles should help you out picking the image resolution and resource folder for different screens. 这些文章可以帮助您挑选不同屏幕的图像分辨率和资源文件夹。

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

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

You have to set window color format. 您必须设置窗口颜色格式。 In your activity put something like this: 在你的活动中添加如下内容:

getWindow().setFormat(PixelFormat.RGBA_8888);

I guess size of image is smaller than the area in which image is displayed. 我猜图像的尺寸小于图像显示的区域。 So, may be image is scaling up and loosing the quality. 因此,可能是图像正在扩大和失去质量。

What you can try is:

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

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

Try antialias this may solved you problem. 尝试antialias这可能会解决你的问题。

Create a bitmap drawable with the below xml. 使用以下xml创建一个可绘制的位图。

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

What you are doing is to set the image in xml that much more depends on what that image resolution support for . 你正在做的是在xml中设置图像更多取决于图像分辨率支持的内容。

there is a number of folders for each supported density of multiple devices , put your image on some suitable folder of dpi . 每个支持的多个设备密度都有多个文件夹,将您的图像放在一些合适的dpi文件夹中。

please refer this link for it http://developer.android.com/guide/practices/screens_support.html 请参阅此链接http://developer.android.com/guide/practices/screens_support.html

see same app icon how behave diffidently in different folder 看到相同的应用程序图标如何在不同的文件夹中表现得很明显

Example application without support for different densities, as shown on low, medium, and high density screens 不支持不同密度的示例应用,如低,中和高密度屏幕所示

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

在此输入图像描述

Example application with good support for different densities (it's density independent), as shown on low, medium, and high density screens. 示例应用,具有对不同密度(它的密度无关)的良好支持,如低,中和高密度屏幕所示。

Just tweak it by making the image a background image. 只需通过将图像作为背景图像来调整它。 Here is a sample code 这是一个示例代码

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

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

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