6

I want to display a png image on android. This is the image file:

enter image description here

The right end is a bit darker than left.

But the quality of image lost on android application(using ImageView):

enter image description here

Please note part in the red frame. The color is not changing smoothly.

But if I use the browser of my android phone, it plays good(so it's not reason of the phone screen):

enter image description here

This is my android code, which is pretty simple:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:background="@drawable/hhh"/>
</LinearLayout>

where hhh is my first image posted here, which is under res/drawable.

I test it on my android phone(android 2.3.6) and android simulator(with android 2.2/2.3/4.0), all do not display good. But it plays good on my android pad(android 4.0.3).

What's the problem, and how to fix it?

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • 1
    Try saving png with alpha channel,(pixels not perfectly opaque) from your image editor. – S.D. Oct 30 '12 at 11:25
  • Have you tried using code to set the ImageView? Using code you can enable more options There's a similar questions whose answer may help u. http://stackoverflow.com/questions/7312996/how-to-improve-the-image-quality-when-images-are-in-drawable-folder – dumbfingers Oct 30 '12 at 11:25
  • 1
    http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/ – Selvin Oct 30 '12 at 11:31

3 Answers3

7

Images in res/drawable are compressed. This is supposed to be lossless, but I've heard of similar issues in the past.

Move it into res/raw, and give it a go.

Richard Taylor
  • 2,702
  • 2
  • 22
  • 44
  • I just tried `res/raw`, but no lucky. I moved the image to `res/raw`, and changed the code to ``, it didn't display well. – Freewind Oct 30 '12 at 11:17
  • 1
    The issue you have is banding, have you tried dithering? This has some options/workarounds http://stackoverflow.com/questions/4769885/androiddither-true-does-not-dither-whats-wrong – Richard Taylor Oct 30 '12 at 11:19
0

Try adding the following to your Activity and see if it helps.

@Override
public void onAttachedToWindow() {
   super.onAttachedToWindow();
   Window window = getWindow();
   //eliminates color banding
   window.setFormat(PixelFormat.RGBA_8888);
}
waqaslam
  • 67,549
  • 16
  • 165
  • 178
-1

This problem is a well-know it is a gradient banding issues, I have this problen and solve by add noise, such as http://planetphotoshop.com/say-goodbye-to-gradient-banding.html

titico
  • 1