[英]How to crop a WebView screen capture?
I would like to take a screenshot of my WebView, then crop it at x,y,w,h. 我想截取WebView的屏幕截图,然后将其裁剪为x,y,w,h。 Here is what I got: 这是我得到的:
private WebView mWebView;
public void onSavePhoto(int top, int left, int width, int height){
Bitmap bitmap = Bitmap.createBitmap(mWebView.getWidth(), mWebView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
mWebView.draw(canvas);
}
Crop using createBitmap 使用createBitmap裁剪
private WebView mWebView;
public void onSavePhoto(int top, int left, int width, int height){
Bitmap bitmap = Bitmap.createBitmap(mWebView.getWidth(), mWebView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
mWebView.draw(canvas);
// crop bitmap:
Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, left, top, width, height);
}
You can do this with these steps 您可以按照以下步骤进行操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.