0

我正在为从网上下载的 PNG 实现图像缓存。

到目前为止效果很好,除了在具有白色背景的图像上,当从缓存(外部存储)读取它们时,获得浅绿色背景。

从网络下载图像时,它们会正确显示。但是在从外部存储保存和加载后,它们会显示为浅绿色背景。

在 3 台设备上测试,问题出在其中 2 台,三星 Galaxy 和 HTC 的愿望。第三个,Galaxy Nexus,没有这个问题。

代码的相关部分:

保存到文件:

FileOutputStream outputStream = new FileOutputStream(fileUri);
image.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.flush();
outputStream.close();

读取文件:

File file = new File(fullCacheDir.toString(), fileName);

从网上下载:

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");
4

1 回答 1

1

我相信问题在于在显示之前将图像从 RGB888 自动转换为 16 位 RGB565 格式。这是一篇关于如何处理这个问题的好文章:Bitmap Format Woes

于 2012-10-02T08:31:16.210 回答