Java Code Examples for android.webkit.WebView#capturePicture()

The following examples show how to use android.webkit.WebView#capturePicture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Purity.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
public boolean checkRenderView(WebView view)
{
    if(state == null)
    {
        setBitmap(view);
        return false;
    }
    else
    {
        Picture p = view.capturePicture();
        Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
        boolean result = newState.equals(state);
        newState.recycle();
        return result;
    }
}
 
Example 2
Source File: Purity.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
public boolean checkRenderView(WebView view)
{
    if(state == null)
    {
        setBitmap(view);
        return false;
    }
    else
    {
        Picture p = view.capturePicture();
        Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
        boolean result = newState.equals(state);
        newState.recycle();
        return result;
    }
}
 
Example 3
Source File: PictureMergeManager.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 对WebView进行截图
 *
 * @param webView
 * @return
 */
private Bitmap captureWebView1(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;
}
 
Example 4
Source File: WebViewCapture.java    From ViewCapture with Apache License 2.0 5 votes vote down vote up
private Bitmap captureWebView(WebView webView) {
    Picture picture = webView.capturePicture();
    int width = picture.getWidth();
    int height = picture.getHeight();
    if (width > 0 && height > 0) {
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
        return bitmap;
    }
    return null;
}
 
Example 5
Source File: ScreenShotHelper.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Bitmap createType1(WebView webView, FileHelper.OnSavedToGalleryListener listener) {
    Picture picture = webView.capturePicture();
    int width = picture.getWidth();
    int height = picture.getHeight();
    Bitmap bitmap = null;
    if (width > 0 && height > 0) {
        bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
    }
    return bitmap;
}
 
Example 6
Source File: ScreenshotTaker.java    From AndroidRipper with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a bitmap of a given WebView.
 *  
 * @param webView the webView to save a bitmap from
 * @return a bitmap of the given web view
 * 
 */

private Bitmap getBitmapOfWebView(final WebView webView){
	Picture picture = webView.capturePicture();
	Bitmap b = Bitmap.createBitmap( picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
	Canvas c = new Canvas(b);
	picture.draw(c);
	return b;
}
 
Example 7
Source File: ScreenUtils.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
private static Bitmap captureWebView(WebView webView) {
    Picture snapShot = webView.capturePicture();
    if (snapShot == null) {
        return null;
    }
    Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),
            snapShot.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    snapShot.draw(canvas);
    return bmp;
}
 
Example 8
Source File: ScreenShoot.java    From Utils with Apache License 2.0 5 votes vote down vote up
/**
 * shoot the web view
 */
public static Bitmap shoot(WebView webView) {
    Picture snapShot = webView.capturePicture();
    Bitmap bitmap = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    snapShot.draw(canvas);
    return bitmap;
}
 
Example 9
Source File: PreviewActivity.java    From writeily-pro with MIT License 5 votes vote down vote up
private Bitmap getBitmapFromWebView(WebView webView) {
    try {
        float scale = 1.0f / getResources().getDisplayMetrics().density;
        Picture picture = webView.capturePicture();
        Bitmap bitmap = Bitmap.createBitmap((int) (picture.getWidth() * scale), (int) (picture.getHeight() * scale), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.scale(scale, scale);
        picture.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 10
Source File: Purity.java    From cordova-android-chromeview with Apache License 2.0 4 votes vote down vote up
public void setBitmap(WebView view)
{
    Picture p = view.capturePicture();
    state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
}
 
Example 11
Source File: Purity.java    From crosswalk-cordova-android with Apache License 2.0 4 votes vote down vote up
public void setBitmap(WebView view)
{
    Picture p = view.capturePicture();
    state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
}