如何添加一个PNG图像作为背景在Android中,没有修改(条纹)? [英] How to add a PNG image as background in Android with no alteration (banding)?

查看:390
本文介绍了如何添加一个PNG图像作为背景在Android中,没有修改(条纹)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加背景,其中包括一个梯度(我确实希望使用图像,而不是Android的XML声明的渐变效果)。

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).

这形象显着搭载Android毁了,把它添加一些蹩脚的条纹无论我尝试的结果是相同的(两个捕获大约在同一区域的扭曲/正常图像):

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) :

正常

我的形象被用作在我的布局XML布局背景:

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

android:background="@drawable/background_gradient_dithered"

我试图用一个中间绘制强制抖动的XML是:

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"/>

我试过有以下code在我的onCreate():

I've tried to have the following code in my onCreate() :

getWindow().setFormat(PixelFormat.RGBA_8888);

这两种尝试改变什么。

Both tries changed nothing.

感谢

推荐答案

正确的解决办法是....我敢打赌,你已经猜它:重新启动Eclipse的我已经学会了,每次在Android上的问题可能是重新启动Eclipse问题。

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".

在一些测试,我可以补充一点,使dethering是没有用的,当格式设置为PixelFormat.RGBA_8888

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

读者应该给看看由@ TenFour04给出了答案,这种方法可避免使刚刚绘制,使抖动。

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);

编辑:

我发现,即使这些技巧的问题,能坚持。您可以尝试modifiy您的PNG有它的alpha层(更改像素的例如99%的透明度),这将迫使Android的编译器不与它玩了。

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.

这篇关于如何添加一个PNG图像作为背景在Android中,没有修改(条纹)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆