본문 바로가기

안드로이드/ADB & Rooting

안드로이드 소스에서 화면캡쳐하는 방법


public void screenshot(View view)throws Exception {      

view.setDrawingCacheEnabled(true);

Bitmap screenshot = view.getDrawingCache();

String filename = "screenshot.png";

try {

File f = new File(Environment.getExternalStorageDirectory(), filename);

f.createNewFile();

OutputStream outStream = new FileOutputStream(f);

screenshot.compress(Bitmap.CompressFormat.PNG, 100, outStream);

outStream.close();

catch (IOException e) {

e.printStackTrace();

}

view.setDrawingCacheEnabled(false);

}