调用截图方法时应用强制退出:
public Bitmap takeScreenShot(Activity activity){
//View是你需要截图的View
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
b1 = view.getDrawingCache();
//获取状态栏高度
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
//获取屏幕长和高
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
//去掉标题栏
b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, b1.getHeight()-statusBarHeight);
view.destroyDrawingCache();
return b;
}
有知道怎么避免这个问题的吗?
------解决方案--------------------
x + width must be <= bitmap.width()宽度超出了你要截的图的宽度~width改成b1.getWidth()试下~