How to add a PNG image as a background in Android without changes (banding)?

I am trying to add a background that includes a gradient (I want to use an image, not android xml, the declared gradient effect).

This image is remarkably corrupted by Android, it adds a bit of crap range, no matter what I try, the result is the same (two captures of approximately the same area of ​​distorted / normal images):

distortednormal

My image is used as the layout background inside my XML layout:

android:background="@drawable/background_gradient_dithered" 

I tried to use intermediate stamina to force smoothing, whose xml:

 <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/background_gradient" android:dither="true" android:antialias="true" android:filter="true"/> 

I tried using the following code in my onCreate ():

 getWindow().setFormat(PixelFormat.RGBA_8888); 

Both have not changed anything.

thanks

+4
source share
3 answers

The correct solution was ... I'm sure you guessed it: restarting Eclipse. I found out about this, every problem on Android can be a "restart of the Eclipse problem".

After some testing, I can add that enabling decryption is not useful if the Format parameter is set to PixelFormat.RGBA_8888

Readers should pay attention to the answer given by @ TenFour04, this approach avoids the use of anti-aliasing only.

 window.addFlags(WindowManager.LayoutParams.FLAG_DITHER); 

EDIT:

I found out that even with these tricks the problem can persist. You can try to modify your PNG to have an alpha layer in it (for example, change the pixel to 99% transparency), this will cause the android compiler not to play with it.

+2
source

Try adding this to onCreate (). Older versions of Android are not anti-aliased by default.

 Window window = getWindow(); window.setFormat(PixelFormat.RGBA_8888); window.addFlags(WindowManager.LayoutParams.FLAG_DITHER); 
+1
source

I worked, just resized the .png files. I put them in mdpi and resized using the source image editor Irfanview <-open to 1024x7xx <- I don’t remember, this is too convenient and I set it to 300 dpi . Therefore, they download it to the tablet and more, I hope this helps :)

0
source

All Articles