How to apply RGBA_8888 and smooth?

I have splash.png with a gradient. But on the screen, this image does not look very 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

source

result

enter image description here

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

The following code gives me a great result in an emulator, but not on a 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"/> 
+3
source share
1 answer

Take a look at this: Horrible background image quality in Android
Or is this anti-aliasing blog post on Android: http://android.amberfog.com/?p=247

In your case, the problem is the xml bitmap. I remember reading somewhere that anti-aliasing only works if the bitmap has a tileMode set.

+1
source

Source: https://habr.com/ru/post/1387105/


All Articles