Comment prendre une capture d'écran d'Android de la Surface d'Affichage?

Je veux en programmant prendre des capture d'écran de mon jeu, tout comme vous obtiendriez dans Eclipse DDMS.

Capture d'écran prises par la solution proposée ici: Procédure de programmation pour prendre une capture d'écran sur Android? et dans la plupart des autres de SORTE que des questions ont Vue sur des éléments visibles, mais pas le 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
background.draw(canvas);

//Draw views
view.draw(canvas);

//Save the screenshot to the file system
FileOutputStream fos = null;
try {
    final File sddir = new File(SCREENSHOTS_LOCATIONS);
    if (!sddir.exists()) {
        sddir.mkdirs();
    }
    fos = new FileOutputStream(SCREENSHOTS_LOCATIONS
            + System.currentTimeMillis() + ".jpg");
    if (fos != null) {
        if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
            Log.d("ScreenShot", "Compress/Write failed");
        }
        fos.flush();
        fos.close();
    }

} catch (FileNotFoundException e) {
    //TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    //TODO Auto-generated catch block
    e.printStackTrace();
}

Toute aide à ce sujet serait très apprécié. Merci.

si vous voulez capturer le point de vue qui ne sont pas visibles ou sous une autre vue?
Double Possible de Android Prendre une Capture d'écran de la Surface d'Affichage Montre l'Écran Noir

OriginalL'auteur Tariq Mahmood | 2013-01-31