Reputation: 278
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:
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.
Upvotes: 7
Views: 5194
Reputation: 2175
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"
/>
Upvotes: 0
Reputation: 7881
What you are doing is to set the image in xml that much more depends on what that image resolution support for .
there is a number of folders for each supported density of multiple devices , put your image on some suitable folder of dpi .
please refer this link for it 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.
Upvotes: 0
Reputation: 17264
Banding occurs mostly when aspect ratio of the image is disturbed.
You could try any one of the following:
Make your image .9.png
. In that case, it will automatically fix any stretches and take care of banding.
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" />
Upvotes: 8
Reputation: 809
You need to resize your image into different sizes and put those into respective drawable folders under res/
Upvotes: 1
Reputation:
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 )
Upvotes: 1
Reputation: 7849
Try antialias this may solved you problem.
Create a bitmap drawable with the below xml.
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background"
android:antialias="true"
android:dither="true" />
Upvotes: 0
Reputation: 16537
You have to set window color format. In your activity put something like this:
getWindow().setFormat(PixelFormat.RGBA_8888);
Upvotes: 2
Reputation: 17105
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/training/multiscreen/index.html
Upvotes: 2