我在 Android 屏幕捕获方面遇到问题。捕获的图像是透明的,而原始图像是不透明的固体 JPEG 文件! 我在许多具有不同操作系统版本的设备上进行了测试,并且所有手机上都存在问题。 这是我的屏幕捕获代码以及最终输出
代码:
final Bitmap rawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(rawBitmap);
rendererView.layout(0, 0, width, height);
rendererView.draw(canvas);
rawBitmap.compress(CompressFormat.PNG, 100, new FileOutputStream("/sdcard/test" + System.currentTimeMillis() + ".png"));
结果:
最佳答案
问题已经解决了。将图像源加载到 ImageView 时,我对 BitmapFactory 选项使用了错误的设置。
代码(之前和之后):
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPurgeable = true;
options.inInputShareable = true;
//options.inPreferredConfig = Config.ARGB_4444; //WRONG
options.inPreferredConfig = Config.ARGB_8888; //CORRECT
bitmap = BitmapFactory.decodeFile(result.filePath(), options);
谢谢大家。
关于android - 捕获布局屏幕截图后,ImageView 是透明的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12758571/