For a splashscreen I use an image which contains a white background (pure white - checked in Photoshop). For some reason it shows a slight green bg vs. the activity's default white bg - as marked in the screenshot. Only in some devices, like the
I add this as single view in a frame layout to the activity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/splashscreen" />
</FrameLayout>
Any idea? I read about RGB888 vs. RGB565 issues, but couldn't find a proper solution.
Note: I sure could make change the white in the image to transparent, but would prefer to understand the problem and find a proper solution.
This is really annoying. I wonder, why so few people encountered this problem as it should appear on all 32-bit displays.
You mentioned right about RGB888 format. The cause of the problem is that regardless of the original bitmap format in the APK files all bitmaps are compressed (in my case into indexed 256-color! wtf?).
I couldn't find the way to prevent it, so if anyone knows the proper solution, please tell.
However, I found two solutions for the white color problem.
1) Per-bitmap: Say, we have a drawable bitmap resource called @drawable/mypng
, which causes the problem. We need to add an additional XML drawable drawable/mypng_nofilter.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/mypng"
android:filter="false"
/>
and use @drawable/mypng_nofilter
instead.
2) For entire activity: In activity onCreate method we need to add
getWindow().setFormat(PixelFormat.RGB_565);
Now the window has 16-bit color depth and all bitmaps appear "properly" white.
Again, I would prefer to have 32-bit color depth, but I don't know how to control compile-time image compression.
I have solved this issue by changing the Bitmap.CompressFormat
type to PNG
instead of JPEG
:
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.nouv);
Bitmap bitmap = (Bitmap)((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With