Example usage for android.graphics Picture getWidth

List of usage examples for android.graphics Picture getWidth

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Get the width 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);/*ww w.  j ava2s .  com*/
    return bitmap;
}

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;//from w  w w  .  java  2s  . co  m
    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 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);//w ww.  ja va2  s .  c  o m
    return bmp;
}

From source file:Main.java

public static Bitmap getWebViewShopshat(WebView webView) {
    webView.setDrawingCacheEnabled(true);
    webView.buildDrawingCache();//from w  w w  . java2  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.
 * /*from   w w w.j  ava  2s.  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:net.sarangnamu.scroll_capture.MainActivity.java

private void scrollCapture() {
    mProgress.setVisibility(View.VISIBLE);
    BkCfg.hideKeyboard(mUrl);/*ww  w.j a va  2s  .  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: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  w w  w.  ja v a 2  s.c o  m

    return bitmap;
}

From source file:rhcad.touchvg.view.internal.ImageCache.java

@SuppressWarnings("unused")
public final Drawable addSVG(Resources res, int id, String name) {
    Drawable drawable = mCache != null ? mCache.get(name) : null;

    if (drawable == null && id != 0 && USE_SVG) {
        try {//from  ww w. jav  a2 s  . com
            final Picture picture = SVG.getFromResource(res, id).renderToPicture();

            if (picture != null && picture.getWidth() > 0) {
                drawable = new PictureDrawable(picture);
                addToCache(name, drawable);
            }
        } catch (SVGParseException e) {
            Log.e(TAG, "Parse resource fail", e);
        }
    }

    return drawable;
}

From source file:rhcad.touchvg.view.internal.ImageCache.java

@SuppressWarnings("unused")
public final Drawable addSVGFile(String filename, String name) {
    Drawable drawable = mCache != null ? mCache.get(name) : null;

    if (drawable == null && name.endsWith(".svg") && USE_SVG) {
        try {/* w  w w .  ja va 2  s . com*/
            final InputStream data = new FileInputStream(new File(filename));
            final Picture picture = SVG.getFromInputStream(data).renderToPicture();

            if (picture != null && picture.getWidth() > 0) {
                drawable = new PictureDrawable(picture);
                addToCache(name, drawable);
            }
            data.close();
        } catch (FileNotFoundException e) {
            Log.e(TAG, "File not found", e);
        } catch (IOException e) {
            Log.e(TAG, "SVG read fail", e);
        } catch (SVGParseException e) {
            Log.e(TAG, "Parse file fail", e);
        }
    }

    return drawable;
}

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  w  w  w  . ja  v  a  2  s  .com*/
        }
    }
    return true;
}