【发布时间】:2011-06-22 08:19:48
【问题描述】:
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的空白文件?
【问题讨论】:
-
它会抛出任何异常吗?
-
不...它不会抛出任何异常...问题在于保存/捕获图像..
-
您似乎不会尝试自己解决该问题。
-
看起来像 this 的副本,尽管使用的是不同的帐户。代码也是一样的...
-
我们正在做同一个项目...我们没有得到答案,所以我再次提出答案..
标签: android button screenshot