开发者

How to add a PNG image as background in Android with no alteration (banding)?

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

This image is remarkably ruined by Android, it add some crappy banding whatever I try the result is the same (two capture of approximately the same region the distorted/normal images) :

How to add a PNG image as background in Android with no alteration (banding)?

How to add a PNG image as background in Android with no alteration (banding)?

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

android:background="@drawable/background_gradient_dithered"

I've tried to used an intermediate drawable to force dither whose xml is :

<?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've tried to have the following code in m开发者_StackOverflowy onCreate() :

getWindow().setFormat(PixelFormat.RGBA_8888);

Both tries changed nothing.

Thanks


The correct solution was .... I bet you've guess it : restarting Eclipse. I've learned it, every problem on Android might be a "restart Eclipse problem".

After some test I can add that enabling dethering is not useful when Format is set to PixelFormat.RGBA_8888

Readers should give a look to the answer given by @TenFour04, this approach can avoid to make drawable just to enable dithering.

window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);

EDIT :

I've found out that even with these tricks the problem can persist. You can try to modifiy your PNG to have an alpha layer in it (change a pixel to a transparency of 99% for example), this would force android compiler to not play with it.


Try adding this in onCreate(). Older versions of Android default to no dithering.

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


I worked it out, just change the size of the .png files. I put them in the mdpi and resized it with Irfanview <-open source image editor to 1024x7xx <- dont remember, this comes too handy and I set it for 300 dpi. So they download it on a tablet and stuff, hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜