3

I have splash.png with gradient. But on screen this image looks not so good ...

My simple .apk for this question consists of:

public class TestditherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

  @Override
  public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setFormat(PixelFormat.RGBA_8888);
  }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitXY"
    android:src="@drawable/test"/>

</LinearLayout>

and test.xml:

<?xml version="1.0" encoding="utf-8"?> 

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

splash.png

source

result

enter image description here

How to apply RGBA_8888 and dither correctly? Where is my mistake?

The next code gives me perfect result in emulator, but not on the real device:

public class TestditherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getWindow().setFormat(PixelFormat.RGBA_8888);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.splash, options);

    findViewById(R.id.linear).setBackgroundDrawable(new BitmapDrawable(gradient));
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Sviatoslav
  • 1,301
  • 2
  • 17
  • 42

1 Answers1

1

Take a look at this: Awful background image quality in Android
Or this blog post about dithering in Android: http://android.amberfog.com/?p=247

In your case the problem is in the bitmap xml. I remember reading somewhere that the dither only works if the bitmap has a tileMode set.

Community
  • 1
  • 1
Jave
  • 31,598
  • 14
  • 77
  • 90
  • I've changed my code and in emulator the result is perfect, but on Galaxy S it is not so good still. – Sviatoslav Dec 19 '11 at 16:14
  • It could be that when you compile the .apk to the device, you get a lower quality image. Or that the device screen does not support that many pixels. If you use a galaxy s with Android 2.1 the dithering is not working properly (see this article: http://www.displaymate.com/Galaxy_S_ShootOut.htm) – Jave Dec 19 '11 at 16:21
  • I am using Galaxy S with android version 2.3.7 – Sviatoslav Dec 19 '11 at 16:37