Example usage for android.graphics Canvas drawPicture

List of usage examples for android.graphics Canvas drawPicture

Introduction

In this page you can find the example usage for android.graphics Canvas drawPicture.

Prototype

public void drawPicture(@NonNull Picture picture) 

Source Link

Document

Save the canvas state, draw the picture, and restore the canvas state.

Usage

From source file:Main.java

public static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),
            pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawPicture(pictureDrawable.getPicture());
    return bitmap;
}

From source file:Main.java

public static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),
            pictureDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawPicture(pictureDrawable.getPicture());
    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 ww  . j  av a 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

private static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable) {
    float intrinsicWidth = (float) pictureDrawable.getIntrinsicWidth();
    float intrinsicHeight = (float) pictureDrawable.getIntrinsicHeight();
    float f = 1.0f;
    if (intrinsicWidth < 600.0f || intrinsicHeight < 600.0f) {
        f = Math.min(600.0f / intrinsicWidth, 600.0f / intrinsicHeight);
        intrinsicWidth = (intrinsicWidth * f) + 0.5f;
        intrinsicHeight = (intrinsicHeight * f) + 0.5f;
    }//from  w ww. ja va  2s .  c o  m
    Bitmap createBitmap = Bitmap.createBitmap((int) intrinsicWidth, (int) intrinsicHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    Matrix matrix = new Matrix();
    matrix.preScale(f, f);
    canvas.concat(matrix);
    canvas.drawPicture(pictureDrawable.getPicture());
    return createBitmap;
}

From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.itemQuit) {

        try {//from   www.  java  2  s .c o m
            dataBaseData.deleteTable(DataBaseData.DB_TABLE_TABS);
        } catch (Exception e) {
            Log.e(TAG, "deleteTable: " + e.getMessage());
        }
        this.finish();
        overridePendingTransition(R.anim.fadein, R.anim.fadeout);

    } else if (item.getItemId() == R.id.itemFeedback) {

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        String aEmailList[] = { "codeskraps@gmail.com" };

        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "sBrowser - Feedback");
        emailIntent.setType("plain/text");

        startActivity(Intent.createChooser(emailIntent, "Send your feedback in:"));

        /*-
        } else if (item.getItemId() == R.id.itemBuyMeAPint) {
                
           try {
              Intent marketIntent = new Intent(Intent.ACTION_VIEW);
              marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
             | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
              startActivity(marketIntent.setData(Uri.parse("market://developer?id=Codeskraps")));
           } catch (Exception e) {
              Intent browserIntent = new Intent(Intent.ACTION_VIEW,
             Uri.parse("http://play.google.com/store/apps/developer?id=Codeskraps"));
              browserIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
             | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
              startActivity(browserIntent);
              Log.e(TAG, e.getMessage());
           }
         */
    } else {

        try {
            Picture picture = webView.capturePicture();
            PictureDrawable pictureDrawable = new PictureDrawable(picture);
            Bitmap bitmap = Bitmap.createBitmap(300, 300, Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            canvas.drawPicture(pictureDrawable.getPicture());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, (OutputStream) bos);
            bitmap.isRecycled();

            BookmarkItem bookmarkItem = new BookmarkItem(webView.getTitle(), webView.getUrl());
            bookmarkItem.setImage(bos.toByteArray());
            sBrowserData.setBookmarkItem(bookmarkItem);
            bos.close();

        } catch (Exception e) {
            Log.e(TAG, "Picture:" + e.getMessage());
            BookmarkItem bookmarkItem = new BookmarkItem("Set title", "Set url");
            bookmarkItem.setImage(null);
            sBrowserData.setBookmarkItem(bookmarkItem);
        }

        SBrowserApplication sBrwoserApp = (SBrowserApplication) getApplication();
        SBrowserActivity.this.startActivity(sBrwoserApp.getMenuIntent(item, SBrowserActivity.this));
        overridePendingTransition(R.anim.fadein, R.anim.fadeout);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.ywesee.amiko.MainActivity.java

/**
 * Converts given picture to a bitmap//from   w ww . j av a2  s  .  com
 * @param picture
 * @return
 */
private static Bitmap pictureDrawable2Bitmap(Picture picture) {
    PictureDrawable pictureDrawable = new PictureDrawable(picture);
    Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),
            pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawPicture(pictureDrawable.getPicture());
    return bitmap;
}