本文介绍了如何把整个活动页面的截图编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何可以采取整个活动的截图在Android上,即使内容是不可见的?例充分的聊天截图,然后生成图像文件?
How can I take screenshot of whole activity on Android, even if content is not visible?Ex. take screenshot of full chat and then generate image file?
我想截图无形的区域了。
I want screenshot invisible area too.
感谢
推荐答案
一种方法是提取当前屏幕的位图,并将其保存。试试这个:
One way is to extract the bitmap of the current screen and save it. Try this:
public void takeScreenshot(){
Bitmap bitmap = getScreenBitmap(); // Get the bitmap
saveTheBitmap(bitmap); // Save it to the external storage device.
}
public Bitmap getScreenBitmap() {
View v= findViewById(android.R.id.content).getRootView();
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache
return b;
}
这篇关于如何把整个活动页面的截图编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!