这应该不是一个太难的问题。我希望能够截取我的布局( View )并通过短信发送。有人可以帮我走几步吗?
谢谢!
编辑: 我猜它不一定是“屏幕截图”,只要我们能以某种方式从 View 中获取所有渲染像素即可。
最佳答案
我在网上找到了一些我能够一起工作的代码 fragment 。
这是一个很好的解决方案:
设置你的根布局:
View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);
获取渲染 View 的函数:
private void getScreen()
{
View content = findViewById(R.id.layoutroot);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/test.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
关于Android通过代码截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5939987/