可能重复: Screenshot Android
我希望通过编程来捕捉屏幕截图(而不是我视图的屏幕截图),并创建了一个应用程序来获取我的视图的屏幕截图。
我试图通过使用Java代码来捕捉设备屏幕截图(就像用户选择任何图像文件一样)(我想要创建服务,从服务中我们可以拍照,但我不知道如何实现这一点)。
我发现了一些使用框架缓冲区fb0的本地代码,但我对此非常熟悉,也不知道如何使用它。
发布于 2012-07-11 10:21:16
下面是一个解决方案,可以将屏幕截图写入sd卡。
设置根布局:
View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);
函数以获取呈现的视图:
private void getScreen()
{
View content = findViewById(R.id.layoutroot);
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();
}
catch (Exception e)
{
e.printStackTrace();
}
}
记住要加上
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
敬你的AndroidManifest。
https://stackoverflow.com/questions/11430418
复制相似问题