如果一个Activity有Surfaceview,我的截图在Surfaceview区域会是黑色的,我该如何修复它?谢谢。
答案 0 :(得分:0)
那么你需要做的就是获取rootview并保存位图绘制缓存。
View v= getRootView();
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap bitmap =v.getDrawingCache();
File file = new File(Environment.getExternalStorageDirectory() + "/game_screen.png";);
try
{
file.createNewFile();
FileOutputStream output= new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, output);
output.close();
}
catch (Exception e)
{
e.printStackTrace();
}
试试这个。