Friday, June 3, 2011

¿How to capture a screenshot programmatically ?

View myView = findViewById(R.id.form);
Bitmap bmp = Bitmap.createBitmap( myView.getMeasuredWidth() , myView.getMeasuredHeight() , Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
myView.draw(canvas);
try {
FileOutputStream out = new FileOutputStream( "/sdcard/screen.jpg" );
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {

e.printStackTrace();

}