public class ScreenCapture extends Activity {
LinearLayout view;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view = (LinearLayout) findViewById(R.id.screen);
Button myBtn = (Button) findViewById(R.id.myBtn);
myBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
View v1 = view.getRootView();
System.out.println("Root View : " + v1);
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
System.out.println("Bitmap : " + bm);
saveScreen(bm);
}
});
}
public void saveScreen(Bitmap bm) {
try {
FileOutputStream out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
}