FYI:
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Picture;
import android.view.View;
import android.webkit.WebView;
public class Capture {
/**
* 截取webView可视区域的截图, 这个方法只截取屏幕中显示出来部分的webView画面,未显示的部分不会被截取。
* @param webView 前提:WebView要设置webView.setDrawingCacheEnabled(true);
* @return
*/
private Bitmap captureWebViewVisibleSize(WebView webView){
Bitmap bmp = webView.getDrawingCache();
return bmp;
}
/**
* 截取webView快照(webView加载的整个内容的大小)
* @param webView
* @return
*/
private Bitmap captureWebView(WebView webView){
Picture snapShot = webView.capturePicture();
Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
snapShot.draw(canvas);
return bmp;
}
/**
* 截屏
* @param context
* @return
*/
private Bitmap captureScreen(Activity context) {
View cv = context.getWindow().getDecorView();
Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
cv.draw(canvas);
return bmp;
}
}