在Android的可怕的背景图像质量 [英] Awful background image quality in Android

查看:311
本文介绍了在Android的可怕的背景图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一个背景,我的活动,但图像质量是不是预期的。

I'm trying to place a background in my activity, but the image quality is not the expected.

图片上面有蓝色条纹的简单的梯度,目前看起来是这样的:

The image has a simple gradient above blue stripes, and currently looks like this:

我的活动布局:     

My activity layout:

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

背景描述符(绘制/ 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,这是actitivy的的LinearLayout背景下的XML文件。不过,我已经尝试了一切,我发现至今。启用抖动,反锯齿,瓦,RGBA_8888模式......你的名字。有没有人有不同的解决方案或想法,我可以尝试一下呢?我会非常感激。

Currently I have an XML file describing a BitmapDrawable, which is the actitivy's LinearLayout background. But I've tried everything I found so far. Enabled dither, antialias, tile, RGBA_8888 modes... You name it. Does anyone have a different solution or idea I could try? I'd be very grateful.

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

Btw, I'm currently developing the app in a Galaxy S II.

推荐答案

首先,请确保您的原始图像看起来不错,所以你不能只是从那里的问题。
然后,在你的onCreate()方法,这样做:

First of all, make sure that your original image looks good so you're not just getting the problem from there.
Then, in your onCreate() method, do:

code1:

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

德precated:

<打击> getWindow()addFlags(WindowManager.LayoutParams.FLAG_DITHER);

和显式地加载图像为32位图像(RGBA-8888配置)增加以下内容,其中加载您的看法:

And to load your image explicitly as a 32-bit image (RGBA-8888 configuration) add the following where you load your views:

code2:

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


不同方法之间的比较: (这些都是从所得到的应用程序的所有截图)


Comparison between different approaches: (these are all screenshots from the resulting application)

我的源图像(64色的左边,24位到右):
此搜索和图像2:
24位
1:原始的 64色图片(此搜索)设置为从布局XML背景:

2:在相同的图像(此搜索),使用的 code1

3:同时使用的 code1 code2 相同的图像(此搜索):

4:IMAGE2,满载 code1 code2 (在这种情况下,抖动是不是每色源和目的使用8位真的很重要):


My source images (64 colors to the left, 24 bit to the right):
image1 and image2:

1: Raw 64-color image (image1) set as background from layout XML:

2: The same image (image1), using code1:

3: The same image (image1) using both code1 and code2:

4: image2, loaded with code1 and code2 (in this case the dithering is not really important as both the source and destination use 8 bits per color):


请注意,在图像3中的结果的工件已经存在于原始图像。

请注意:如果有谁知道如何缩小图像降一点,随意编辑这个职位......

Note: if anyone knows how to shrink the images down a bit, feel free to edit this post...

这篇关于在Android的可怕的背景图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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