[英]android make screenshot of entire layout
I am doing screenshot and returning a bitmap using the next method. 我正在做屏幕截图,并使用下一个方法返回位图。
public Bitmap takeScreenShot(View view) {
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
view.buildDrawingCache();
if (view.getDrawingCache() == null) return null;
Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
view.destroyDrawingCache();
return snapshot;
}
and i call it something like this 我称之为这样的东西
takeScreenShot(getWindow().getDecorView().findViewById(android.R.id.content))
My problem is that i have some layout that contain listviews/gridviews , how can i screenshot the entire layout extended ? 我的问题是我有一些包含listviews / gridviews的布局,我如何截图整个扩展的布局?
Try this code: 试试这个代码:
public static Bitmap getBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}
Edit: 编辑:
Bitmap bitmap = Bitmap.createBitmap(scrollView.getChildAt(0).getWidth(), scrollView.getChildAt(0).getHeight(), Bitmap.Config.ARGB_8888);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.