Example usage for android.graphics Picture getHeight

List of usage examples for android.graphics Picture getHeight

Introduction

In this page you can find the example usage for android.graphics Picture getHeight.

Prototype

public int getHeight() 

Source Link

Document

Get the height of the picture as passed to beginRecording.

Usage

From source file:Main.java

public static Bitmap pictureDrawable2Bitmap(Picture picture) {
    Bitmap bitmap = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    picture.draw(canvas);//  w  ww . jav a 2  s. com
    return bitmap;
}

From source file:Main.java

public static Bitmap captureWebView(WebView webView) {
    Picture snapShot = webView.capturePicture();
    Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    snapShot.draw(canvas);//from  ww  w.j a v a 2  s  .  c  o m
    return bmp;
}

From source file:Main.java

public static Bitmap getWebViewShotshatByPicture(WebView webView) {
    Picture picture = webView.capturePicture();
    int width = picture.getWidth();
    int height = picture.getHeight();
    Bitmap bw = null;/* w  ww. ja  va 2 s  .c om*/
    if (width > 0 && height > 0) {
        bw = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bw);
        //picture.draw(canvas);
        canvas.drawPicture(picture);
    }
    return bw;
}

From source file:Main.java

public static Bitmap getWebViewShopshat(WebView webView) {
    webView.setDrawingCacheEnabled(true);
    webView.buildDrawingCache();//from w  w  w  .  j  av  a  2  s.com
    Picture snapShot = webView.capturePicture();
    Bitmap bitmap = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888);
    //bitmap.eraseColor(Color.WHITE);

    Canvas c = new Canvas(bitmap);
    int state = c.save();
    webView.draw(c);
    //c.restoreToCount(state);
    c.restore();
    webView.destroyDrawingCache();

    return bitmap;
}

From source file:Main.java

/**
 * @brief      Converting picture to bitmap array.
 * // ww  w  .  j  a  v a 2  s  .  c o m
 * @author     daiping.zhao
 * @param      bm   [IN]  bitmap object
 * 
 * @return     Return converted bytes array
 */
public static Bitmap pictureToBitmap(Picture picture, int width, int height) {
    Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(b);

    // May need to tweak these values to determine what is the
    // best scale factor
    int picWidth = picture.getWidth();
    int picHeight = picture.getHeight();
    float scaleFactorX = 1.0f;
    float scaleFactorY = 1.0f;
    if (picWidth > 0) {
        scaleFactorX = (float) width / (float) picWidth;
    } else {
        return null;
    }

    if (picWidth > picHeight) {
        // If the device is in landscape and the page is shorter
        // than the height of the view, stretch the thumbnail to fill the
        // space.
        scaleFactorY = (float) height / (float) picHeight;
    } else {
        // In the portrait case, this looks nice.
        scaleFactorY = scaleFactorX;
    }

    canvas.scale(scaleFactorX, scaleFactorY);

    picture.draw(canvas);
    return b;
}

From source file:nirwan.cordova.plugin.printer.Printer.java

private Bitmap takeScreenshot(WebView page) {
    Picture picture = page.capturePicture();
    Bitmap bitmap = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    picture.draw(canvas);//from ww w  .j ava2s  . co m

    return bitmap;
}

From source file:net.sarangnamu.scroll_capture.MainActivity.java

private void scrollCapture() {
    mProgress.setVisibility(View.VISIBLE);
    BkCfg.hideKeyboard(mUrl);//from   ww w.j  a v  a 2 s.  com

    if (mLog.isDebugEnabled()) {
        String log = "";
        log += "===================================================================\n";
        log += "CAPTURE START\n";
        log += "===================================================================\n";
        mLog.debug(log);
    }

    new AsyncTask<Object, Integer, Boolean>() {
        Bitmap mBmp;

        @Override
        protected void onPreExecute() {
            int w, h;
            try {
                Picture pic = mWeb.capturePicture();

                w = pic.getWidth();
                h = pic.getHeight();
            } catch (Exception e) {
                w = mWeb.getMeasuredWidth();
                h = mWeb.getMeasuredHeight();
            }

            mWeb.measure(
                    View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED,
                            View.MeasureSpec.UNSPECIFIED),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            mBmp = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);

            Canvas canvas = new Canvas(mBmp);
            mWeb.draw(canvas);
        }

        @Override
        protected Boolean doInBackground(Object... objects) {
            Context context = (Context) objects[0];

            File dnPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            File ssPath = new File(dnPath, "screenshot");
            if (!ssPath.exists()) {
                ssPath.mkdirs();
            }

            String fileName = "test.png"; // DateFormat.format("yyyyMMdd-HHmmss", new Date()) + ".png";
            File ssFile = new File(ssPath, fileName);

            try {
                FileOutputStream os = new FileOutputStream(ssFile);
                mBmp.compress(Bitmap.CompressFormat.PNG, 90, os);
                os.flush();
                os.close();

                sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                        Uri.parse("file://" + ssFile.getAbsolutePath())));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (mBmp != null) {
                mBmp.recycle();
                mBmp = null;
            }

            if (mLog.isDebugEnabled()) {
                String log = "";
                log += "===================================================================\n";
                log += "CAPTURE END\n";
                log += "===================================================================\n";
                mLog.debug(log);
            }

            mProgress.setVisibility(View.GONE);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, MainActivity.this);
}

From source file:android.webkit.cts.WebViewTest.java

private boolean isPictureFilledWithColor(Picture picture, int color) {
    if (picture.getWidth() == 0 || picture.getHeight() == 0)
        return false;

    Bitmap bitmap = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Config.ARGB_8888);
    picture.draw(new Canvas(bitmap));

    for (int i = 0; i < bitmap.getWidth(); i++) {
        for (int j = 0; j < bitmap.getHeight(); j++) {
            if (color != bitmap.getPixel(i, j)) {
                return false;
            }//from  www  . jav  a 2s . c o m
        }
    }
    return true;
}