我正在使用以下代码截取 TableLayout 的屏幕截图。我必须补充一点,我的 android 应用程序的主题设置为 LIGHT。它在模拟器屏幕上显示得非常好(就像它应该的那样)......但是,一旦截取屏幕截图,图像就会变成这样......任何人都可以帮助指出我在这里做错了什么?谢谢!
private void getScreen()
{
View content = findViewById(R.id.TransactionLog);
content.setDrawingCacheEnabled(true);
content.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache());
content.setDrawingCacheEnabled(false); // clear drawing cache
File file = new File(Environment.getExternalStorageDirectory() +
File.separator + "logDetails.jpeg");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.flush();
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
if (!file.exists()) {
sendmail();
}
}
最佳答案
1) 你应该使用png。 Jpeg 用于照片(基本上)。
2) 因为您使用的是 Jpeg,所以我假设那些黑色区域否则是透明的。 PNG 支持透明度。 Jpeg 没有。我没有尝试过 drawingCache,所以也许它也不支持透明度,我完全错了,但这是我的猜测。
所以,总结一下,试试Png。
关于android - 屏幕截图错误 (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8012172/