如何申请RGBA_8888正确抖动? [英] How to apply RGBA_8888 and dither correctly?

查看:159
本文介绍了如何申请RGBA_8888正确抖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经splash.png梯度。但屏幕上看到此图像看起来不那么好...

我的简单的 .apk文件作为这个问题包括:

 公共类TestditherActivity延伸活动{
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
}  @覆盖
  公共无效onAttachedToWindow(){
    super.onAttachedToWindow();
    。getWindow()和setFormat(PixelFormat.RGBA_8888);
  }
}< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / LinearLayout01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:比重=中心>< ImageView的
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:scaleType =fitXY
    机器人:SRC =@绘制/测试/>< / LinearLayout中>

的test.xml

 <?XML版本=1.0编码=UTF-8&GT?;<位图
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:SRC =@绘制/扑通
机器人:抗锯齿=真
机器人:抖动=真/>

splash.png

结果

如何 RGBA_8888 抖动正确应用?哪里是我的错?

接下来的code给我在模拟器完美的结果,但不是真正的设备上:

 公共类TestditherActivity延伸活动{
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    。getWindow()和setFormat(PixelFormat.RGBA_8888);
    。getWindow()addFlags(WindowManager.LayoutParams.FLAG_DITHER);    BitmapFactory.Options选项=新BitmapFactory.Options();
    options.in preferredConfig = Bitmap.Config.ARGB_8888;
    位图梯度= BitmapFactory.de codeResource(getResources(),R.drawable.splash,期权);    findViewById(R.id.linear).setBackgroundDrawable(新BitmapDrawable(梯度));
}
}

的main.xml

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID /线性
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>


解决方案

看看这个:
<一href=\"http://stackoverflow.com/questions/8417608/awful-background-image-quality-in-android/8417703#8417703\">Awful在Android的结果的背景图像质量
或者这个博客帖子大约在Android的抖动: http://android.amberfog.com/?p=247

在您的情况下,问题是位图XML。我记得读书的地方,如果位图有TILEMODE集抖动才起作用。

I have splash.png with gradient. But on screen this image looks not so good ...

My simple .apk for this question consists of:

public class TestditherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

  @Override
  public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setFormat(PixelFormat.RGBA_8888);
  }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitXY"
    android:src="@drawable/test"/>

</LinearLayout>

and test.xml:

<?xml version="1.0" encoding="utf-8"?> 

<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/splash"
android:antialias="true"
android:dither="true" />

splash.png

result

How to apply RGBA_8888 and dither correctly? Where is my mistake?

The next code gives me perfect result in emulator, but not on the real device:

public class TestditherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getWindow().setFormat(PixelFormat.RGBA_8888);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

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

    findViewById(R.id.linear).setBackgroundDrawable(new BitmapDrawable(gradient));
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

解决方案

Take a look at this: Awful background image quality in Android
Or this blog post about dithering in Android: http://android.amberfog.com/?p=247

In your case the problem is in the bitmap xml. I remember reading somewhere that the dither only works if the bitmap has a tileMode set.

这篇关于如何申请RGBA_8888正确抖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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