2011-12-19 22 views
3

我有splash.png漸變。但是屏幕上看到此圖像看起來不那麼好......如何正確應用RGBA_8888和抖動?

我簡單的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

source

結果

enter image description here

如何申請RGBA_8888抖動是否正確?我的錯誤在哪裏?

下一個代碼給我完美的結果在模擬器,但不是真正的設備上:

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

回答

1

在此請看: Awful background image quality in Android
或者這篇關於Android中抖動的博客文章:http://android.amberfog.com/?p=247

在你的情況下,問題出在位圖xml中。我記得在某處讀到抖動只有在位圖有tileMode設置時才起作用。

+0

我已經改變了我的代碼,並在模擬器中的結果是完美的,但在Galaxy S上它仍然不是很好。 – Sviatoslav 2011-12-19 16:14:17

+0

這可能是當您將.apk編譯到設備時,您會得到較低質量的圖像。或者設備屏幕不支持那麼多像素。如果您在Android 2.1上使用星系s,抖動無法正常工作(請參閱此文章:http://www.displaymate.com/Galaxy_S_ShootOut.htm) – Jave 2011-12-19 16:21:15

+0

我使用Galaxy S與Android 2.3.7版 – Sviatoslav 2011-12-19 16:37:01