-2
Button button = (Button)findViewById(R.id.btnTakeScreenshot);
button.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
final View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File(Environment.getExternalStorageDirectory() + "/test.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
Toast.makeText(content.getContext(), "HELLO", Toast.LENGTH_SHORT);
}
catch (Exception e)
{
System.out.print("error");
e.printStackTrace();
}
}
});
上面的代碼是捕獲一個截圖,但它創建零kb的空白文件?android截圖?
它會拋出任何異常嗎? – Egor
不...它不會拋出任何異常...問題是在保存/捕獲圖像.. – alpesh
它不會出現,如果你自己試圖解決這個問題。 –