android - Android中糟糕的背景图像质量

标签 android image background gradient

我正在尝试在我的 Activity 中放置背景,但图像质量不是预期的。

图片在蓝色条纹上方有一个简单的渐变,目前看起来像这样:

LinearLayout background

我的 Activity 布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background_register"
    android:drawingCacheQuality="high" >
</LinearLayout>

背景描述符(drawable/background_register):

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:antialias="true"
    android:dither="true"
    android:filter="true"
    android:tileMode="repeat"
    android:gravity="center"
    android:src="@drawable/background_blue_565" />

目前我有一个描述 BitmapDrawable 的 XML 文件,它是 Activity 的 LinearLayout 背景。但我已经尝试了到目前为止我发现的一切。启用抖动、抗锯齿、平铺、RGBA_8888 模式......你的名字。有没有人有不同的解决方案或想法我可以尝试?我将不胜感激。

顺便说一句,我目前正在 Galaxy S II 中开发应用程序。

最佳答案

首先,确保您的原始图像看起来不错,这样您就不会从那里得到问题。
然后,在您的 onCreate() 方法中,执行:

code1:

getWindow().getDecorView().getBackground().setDither(true);
getWindow().setFormat(PixelFormat.RGBA_8888);

已弃用:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

要将您的图像显式加载为 32 位图像(RGBA-8888 配置),请在加载 View 的位置添加以下内容:

代码2:

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

findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient));


不同方法的比较: (这些都是生成的应用程序的屏幕截图)

我的源图像(左侧 64 色,右侧 24 位):
image1 和 image2:
64-color 24 bit
1:原始 64 色 图像 (image1) 从布局 XML 设置为背景:
Raw image
2:同一张图片(image1),使用code1:
Dithered image
3:使用 code1code2 的相同图像(image1):
explicit 32bit
4:image2,加载了 code1code2(在这种情况下,抖动并不重要,因为源和目标都使用每种颜色 8 位):
higher original quality

请注 Intent 像 3 中生成的伪影如何已存在于原始图像中。

注意:如果有人知道如何将图像缩小一点,请随时编辑这篇文章......

关于android - Android中糟糕的背景图像质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8417608/

相关文章:

CSS - 背景图像定位

python - 带有 .nii.gz 文件的医学成像 (PyRadiomics)

css - float :right and relative positioning

java - 使用 Java 识别图形中的线条

android - BroadcastReceiver 的 Manifest 和 Programmatic 注册的主要区别

OpenGL 抗锯齿和背景四边形

ruby-on-rails - Rails 最好的后台作业管理库是什么?

带有 XML 空标签的 Android list ?

android - ListView 完整按钮消失

android - 混合应用程序在性能上是否优于 native 应用程序