Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horrible ImageView bitmap quality?

I've got a splash screen with an ImageView playing the part of a background. 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. Here is a screenshot:

enter image description here

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. Here is the XML code for this activity:

<?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); as suggested which made a visible difference but the banding is still present. This is the image I'm using as the background.

like image 823
Michael Zimmerman Avatar asked Apr 04 '13 11:04

Michael Zimmerman


People also ask

How do I increase the quality of a bitmap image?

In the Library window, right-click (Windows) or control-click (Macintosh) on the bitmap and select Properties. Choose Lossless from the Compression pop-up menu and click OK. This will cause Flash to render the image at the original imported quality and will probably cause the SWF file size to increase considerably.

Can ImageView be clickable?

You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView .

What is adjustViewBounds?

android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.

Can ImageView display video?

ImageView is a control which display image on android and support RGB image, so setting the data of ImageView every period can generate dynamic video.


1 Answers

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. 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" />
    
like image 145
Gaurav Arora Avatar answered Sep 30 '22 14:09

Gaurav Arora