Example usage for android.graphics.drawable PictureDrawable getPicture

List of usage examples for android.graphics.drawable PictureDrawable getPicture

Introduction

In this page you can find the example usage for android.graphics.drawable PictureDrawable getPicture.

Prototype

public Picture getPicture() 

Source Link

Document

Return the picture associated with the drawable.

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

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;
    }/*  w w  w. j  a v a 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 ww  w.  ja v  a2 s .  c om
            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/*ww w.j  a v a2  s . co m*/
 * @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;
}