Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image does not show completely white despite it's correctly white

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

ImageView graphic shows now white background despite the image uses white

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.

like image 203
Bachi Avatar asked May 07 '12 16:05

Bachi


2 Answers

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.

like image 78
Axel Avatar answered Jan 03 '23 14:01

Axel


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);
like image 42
Silvain Avatar answered Jan 03 '23 14:01

Silvain