小编Tar*_*ood的帖子

如何截取Android的Surface View截图?

我想以编程方式拍摄我的游戏的屏幕截图,就像你进入Eclipse DDMS一样.

通过此处提出的解决方案截取屏幕截图:如何以编程方式在Android中截取屏幕截图?在大多数其他SO问题中,只有View元素可见,但SurfaceView不是.

SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);

// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
    .obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);

// Draw background …
Run Code Online (Sandbox Code Playgroud)

android screenshot surfaceview

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

screenshot ×1

surfaceview ×1