我有一个在 ImageView
中显示图像的应用程序,但我遇到了专门针对 Android 4.1.2 的问题。已确认无法在三个独立的 4.1.2 设备上运行,而在 2.3.7、4.2.1、4.3 和 4.4.2 上运行。该错误发生在几个不同的图像上,但不是全部。某些特定的 JPEG 文件似乎无法按预期工作。
它的实际外观以及它在 Android 4.1.2 上的显示方式:
上图(左)就是这样一个有问题的图像文件。
设置显示图像背后的代码摘要是:
Bitmap bitmap, background;
ImageView imageView = (ImageView)findViewById(R.id.imageView);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPurgeable = true;
options.inInputShareable = true;
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dog, options);
background = bitmap.copy(Bitmap.Config.RGB_565, true);
Canvas canvas = new Canvas(background);
canvas.drawBitmap(bitmap, 0, 0, null);
// Some calls to canvas.drawText(....) here, but doesn't have to happen for the error to occur
imageView.setImageBitmap(background);
我想我可以在 Photoshop 中调整上述照片的大小并重新保存它以使其正常工作,但不知道为什么。因为我有几个,所以我宁愿不必这样做。
我想知道 Android 4.1.2 上这个错误的来源是什么,是否有一些编程方法可以修复它?
我在谷歌 View “倾斜”、“倾斜”、“扭曲”和类似的情况下试过运气,但很少有人提到它,也没有修复。这是我发现的带有屏幕截图的提及:
最佳答案
基于 rupps 的评论我改变了:
bitmap.copy(Bitmap.Config.RGB_565, true)
收件人:
bitmap.copy(Bitmap.Config.ARGB_8888, true)
这确实解决了 4.1.2 设备的问题,同时所有其他测试设备的功能保持相似。这确实以编程方式解决了我的问题。但是请注意,它确实需要双倍的内存,因为每个像素都存储在 4 个字节而不是 2 个字节上。
至于问题的根源,我是从the documentation of RGB_565
上看到的那:
This configuration can produce slight visual artifacts depending on the configuration of the source.
我认为这主要与 strip /颜色/抖动问题有关,这并不能解释特定于版本的问题,但也许为什么这个设置很麻烦。
关于android - Android 4.1.2 上 ImageView 中的倾斜图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25921458/