capture screen

FYI:java

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;

    }
}
相關文章
相關標籤/搜索