-1

如果一个 Activity 有 Surfaceview,我的屏幕截图在 Surfaceview 区域会是黑色的,我该如何解决?谢谢 。

4

1 回答 1

0

那么你需要做的是获取根视图并保存位图绘图缓存。

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();
}

尝试这个。

于 2013-10-10T02:43:46.713 回答