Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White is not white

Tags:

android

bitmap

When dealing with some bitmaps in Android I noticed that the white used in views is not always the same white rendered on bitmaps. Consider this screenshot.

enter image description here

The background white is from a view with white background color.

The foreground "white" is from a white bitmap decoded from the SD card, displayed in an ImageView. This bitmap is decoded using RGB_565 as follows:

BitmapFactory.Options resample = new BitmapFactory.Options();
resample.inPreferredConfig = Config.RGB_565;
resample.inSampleSize = sampleSize;
return BitmapFactory.decodeFile(filePath, resample);

For reference, here's the bitmap.

Why is this and how can it be fixed?

like image 943
hpique Avatar asked Mar 22 '11 19:03

hpique


People also ask

Is white really a color?

Some consider white to be a color, because white light comprises all hues on the visible light spectrum. And many do consider black to be a color, because you combine other pigments to create it on paper. But in a technical sense, black and white are not colors, they're shades. They augment colors.

Why is white not a Colour?

In physics, a color is visible light with a specific wavelength. Black and white are not colors because they do not have specific wavelengths. Instead, white light contains all wavelengths of visible light. Black, on the other hand, is the absence of visible light.

What makes the color white?

Colors like white and pink are not present in the spectrum because they are the result of our eyes' mixing wavelengths of light. White is what we see when all wavelengths of light are reflected off an object, while pink is a mix of the red and violet wavelengths.

Is there different shades of white?

Colors often considered "shades of white" include cream, eggshell, ivory, Navajo white, and vanilla. Even the lighting of a room, however, can cause a pure white to be perceived as off-white. Off-white colors were pervasively paired with beiges in the 1930s, and especially popular again from roughly 1955 to 1975.


2 Answers

I have the same issue and after some experiments I noticed that commenting <uses-sdk> solves the problem. Any value for android:minSdkVersion above 3 will make this effect appear (removing <uses-sdk> tag effectively changes minSdkVersion to 1.

like image 127
smok Avatar answered Nov 15 '22 13:11

smok


Try setting getWindow().setFormat(PixelFormat.RGB_565) in your onCreate.

The default format seems to change based on SDK version and device type, so just force it to stay at RGB_565

like image 41
VicVu Avatar answered Nov 15 '22 13:11

VicVu