I’m implementing an image cache for PNGs, downloaded from the web.
Works well so far, besides that on images with a white background, get a light-green background, when they are read from the cache (external storage).
When the images are downloaded from the web, they are displayed correctly. But after saving and loading from external storage they show this light green background.
Tested on 3 devices, the problem was in 2 of them, a Samsung Galaxy and HTC desire. The third one, a Galaxy Nexus, has not this problem.
The relevant parts of code:
Save to file:
FileOutputStream outputStream = new FileOutputStream(fileUri);
image.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.flush();
outputStream.close();
Read file:
File file = new File(fullCacheDir.toString(), fileName);
Download from web:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
HttpResponse response = httpClient.execute(request);
InputStream is = response.getEntity().getContent();
TypedValue typedValue = new TypedValue();
typedValue.density = TypedValue.DENSITY_DEFAULT;
Drawable drawable = Drawable.createFromResourceStream(null, typedValue, is, "src");
I believe that the problem is in autoconverting image from RGB888 to a 16-bit RGB565 format before displaying it. Here is a good article about how to deal with this problem: Bitmap Format Woes .