【问题标题】:How to apply RGBA_8888 and dither correctly?如何正确应用 RGBA_8888 和抖动?
【发布时间】:2011-12-19 15:16:20
【问题描述】:

我有带有渐变的 splash.png。但在屏幕上,这张图片看起来不太好......

我对这个问题的简单 .apk 包括:

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>

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

结果

如何正确应用RGBA_8888dither?我的错在哪里?

下一个代码在模拟器中给了我完美的结果,但在真实设备上却没有:

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

ma​​in.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"/>

【问题讨论】:

    标签: android


    【解决方案1】:

    看看这个: Awful background image quality in Android
    或者这篇关于 Android 抖动的博文:http://android.amberfog.com/?p=247

    在您的情况下,问题出在位图 xml 中。我记得在某处读到,抖动仅在位图设置了 tileMode 时才有效。

    【讨论】:

    • 我更改了代码,在模拟器中结果很完美,但在 Galaxy S 上还是不太好。
    • 可能是当您将 .apk 编译到设备时,您得到的图像质量较低。或者设备屏幕不支持那么多像素。如果您在 Android 2.1 中使用 Galaxy s,则抖动无法正常工作(请参阅本文:displaymate.com/Galaxy_S_ShootOut.htm
    • 我正在使用带有 android 版本 2.3.7 的 Galaxy S
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-06-19
    • 2021-08-27
    相关资源
    最近更新 更多