android.graphics.Picture

Here are the examples of the java api class android.graphics.Picture taken from open source projects.

1. SVG#renderViewToPicture()

Project: XDroidAnimation
File: SVG.java
/**
     * Renders this SVG document to a Picture object using the specified view defined in the document.
     * <p/>
     * A View is an special element in a SVG document that describes a rectangular area in the document.
     * Calling this method with a {@code viewId} will result in the specified view being positioned and scaled
     * to the viewport.  In other words, use {@link #renderToPicture()} to render the whole document, or use this
     * method instead to render just a part of it.
     *
     * @param viewId         the id of a view element in the document that defines which section of the document is to
     *                       be visible.
     * @param widthInPixels  the width of the initial viewport
     * @param heightInPixels the height of the initial viewport
     * @return a Picture object suitable for later rendering using {@code Canvas.drawPicture()},
     * or null if the viewId was not found.
     */
public Picture renderViewToPicture(String viewId, int widthInPixels, int heightInPixels) {
    SvgObject obj = this.getElementById(viewId);
    if (obj == null)
        return null;
    if (!(obj instanceof SVG.View))
        return null;
    SVG.View view = (SVG.View) obj;
    if (view.viewBox == null) {
        Log.w(TAG, "View element is missing a viewBox attribute.");
        return null;
    }
    Picture picture = new Picture();
    Canvas canvas = picture.beginRecording(widthInPixels, heightInPixels);
    Box viewPort = new Box(0f, 0f, (float) widthInPixels, (float) heightInPixels);
    SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, viewPort, this.renderDPI);
    renderer.renderDocument(this, view.viewBox, view.preserveAspectRatio, false);
    picture.endRecording();
    return picture;
}

2. SVG#renderToPicture()

Project: XDroidAnimation
File: SVG.java
/**
     * Renders this SVG document to a Picture object.
     *
     * @param widthInPixels  the width of the initial viewport
     * @param heightInPixels the height of the initial viewport
     * @return a Picture object suitable for later rendering using {@code Canvas.darwPicture()}
     */
public Picture renderToPicture(int widthInPixels, int heightInPixels) {
    Picture picture = new Picture();
    Canvas canvas = picture.beginRecording(widthInPixels, heightInPixels);
    Box viewPort = new Box(0f, 0f, (float) widthInPixels, (float) heightInPixels);
    SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, viewPort, this.renderDPI);
    renderer.renderDocument(this, null, null, false);
    picture.endRecording();
    return picture;
}

3. PictureBitmapTextureAtlasSource#onLoadBitmap()

Project: tilt-game-android
File: PictureBitmapTextureAtlasSource.java
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public Bitmap onLoadBitmap(final Config pBitmapConfig) {
    final Picture picture = this.mPicture;
    if (picture == null) {
        Debug.e("Failed loading Bitmap in " + this.getClass().getSimpleName() + ".");
        return null;
    }
    final Bitmap bitmap = Bitmap.createBitmap(this.mTextureWidth, this.mTextureHeight, pBitmapConfig);
    final Canvas canvas = new Canvas(bitmap);
    final float scaleX = (float) this.mTextureWidth / this.mPicture.getWidth();
    final float scaleY = (float) this.mTextureHeight / this.mPicture.getHeight();
    canvas.scale(scaleX, scaleY, 0, 0);
    picture.draw(canvas);
    return bitmap;
}

4. MapUtils#getPictureFromBitmap()

Project: MapView
File: MapUtils.java
/**
     * bitmap to picture
     *
     * @param bitmap
     * @return
     */
public static Picture getPictureFromBitmap(Bitmap bitmap) {
    Picture picture = new Picture();
    Canvas canvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight());
    canvas.drawBitmap(bitmap, null, new RectF(0f, 0f, (float) bitmap.getWidth(), (float) bitmap.getHeight()), null);
    picture.endRecording();
    return picture;
}

5. PictureBitmapTextureAtlasSource#onLoadBitmap()

Project: AndEngine
File: PictureBitmapTextureAtlasSource.java
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public Bitmap onLoadBitmap(final Config pBitmapConfig) {
    final Picture picture = this.mPicture;
    if (picture == null) {
        Debug.e("Failed loading Bitmap in " + this.getClass().getSimpleName() + ".");
        return null;
    }
    final Bitmap bitmap = Bitmap.createBitmap(this.mTextureWidth, this.mTextureHeight, pBitmapConfig);
    final Canvas canvas = new Canvas(bitmap);
    final float scaleX = (float) this.mTextureWidth / this.mPicture.getWidth();
    final float scaleY = (float) this.mTextureHeight / this.mPicture.getHeight();
    canvas.scale(scaleX, scaleY, 0, 0);
    picture.draw(canvas);
    return bitmap;
}

6. PXImagePaint#applyFillToPath()

Project: pixate-freestyle-android
File: PXImagePaint.java
public void applyFillToPath(Path path, Paint paint, Canvas context) {
    context.save();
    // clip to path
    context.clipPath(path);
    // do the gradient
    Rect bounds = new Rect();
    context.getClipBounds(bounds);
    Picture image = imageForBounds(bounds);
    // draw
    if (image != null) {
        // TODO - Blending mode? We may need to convert the Picture to a
        // Bitmap and then call drawBitmap
        context.drawPicture(image);
    }
    context.restore();
}

7. ScreenshotTaker#getBitmapOfWebView()

Project: robotium
File: ScreenshotTaker.java
/**
	 * 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;
}

8. SnapshotHelper#takeWebViewSnapshot()

Project: Cafe
File: SnapshotHelper.java
/**
     * Take a whole snapshot of a WebView.
     * 
     * @param webView
     *            target webview
     * @param savePath
     *            e.g. /sdcard/webview.jpg
     */
public static void takeWebViewSnapshot(WebView webView, String savePath) {
    Picture picture = webView.capturePicture();
    Bitmap bmp = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmp);
    picture.draw(c);
    outputToFile(savePath, bmp);
}

9. PXShapeView#onDraw()

Project: pixate-freestyle-android
File: PXShapeView.java
@Override
protected void onDraw(Canvas canvas) {
    canvas.getClipBounds(bounds);
    Picture picture = renderToImage(bounds);
    canvas.drawPicture(picture);
}

10. PXImagePaint#imageForBounds()

Project: pixate-freestyle-android
File: PXImagePaint.java
/**
     * Returns a {@link Picture} instance with the loaded {@link Bitmap} or SVG
     * graphics in it.
     * 
     * @param bounds
     * @return A {@link Picture}
     */
public Picture imageForBounds(Rect bounds) {
    Picture image = null;
    if (imageURL != null) {
        initRemoteLoader(bounds);
        // create image
        try {
            image = new Picture();
            Canvas canvas = image.beginRecording(bounds.width(), bounds.height());
            if (hasSVGImageURL()) {
                // for android, instead of using the PXShapeView (which
                // requires a Context), we directly load the scene with
                // PXSVGLoader.loadFromURL(URL)
                PXShapeDocument document;
                if (remoteSVGLoader != null) {
                    document = (PXShapeDocument) remoteSVGLoader.get();
                } else {
                    document = PXSVGLoader.loadFromStream(UrlStreamOpener.open(imageURL));
                }
                document.setBounds(new RectF(bounds));
                document.render(canvas);
            } else {
                // read the data as a bitmap image
                InputStream inputStream = null;
                try {
                    Drawable d = null;
                    if (remoteBitmapLoader != null) {
                        d = getDrawable(remoteBitmapLoader.get());
                    } else {
                        inputStream = UrlStreamOpener.open(imageURL);
                        // Try to load this data as a NinePatchDrawable. The
                        // fallback here, in case the bitmap is not
                        // nine-patch, is BitmapDrawable. Also, when the png
                        // is loaded from the assets directory, we need to
                        // compile/encode it via the "aapt" tool first!
                        // Otherwise, it will not load the nine-patch chunk
                        // data.
                        d = NinePatchDrawable.createFromStream(inputStream, null);
                    }
                    if (d == null) {
                        d = new PXBorderOverlay(Color.RED, 2);
                    }
                    d.setBounds(bounds);
                    d.draw(canvas);
                } finally {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                }
            }
        } catch (Exception e) {
            PXLog.e(TAG, e, "Error loading a PXImagePaint from " + imageURL);
        } finally {
            image.endRecording();
        }
    }
    return image;
}

11. Purity#setBitmap()

Project: crosswalk-cordova-android
File: Purity.java
public void setBitmap(WebView view) {
    Picture p = view.capturePicture();
    state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
}

12. Purity#setBitmap()

Project: cordova-android-chromeview
File: Purity.java
public void setBitmap(WebView view) {
    Picture p = view.capturePicture();
    state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
}

13. Purity#setBitmap()

Project: cordova-android
File: Purity.java
public void setBitmap(WebView view) {
    Picture p = view.capturePicture();
    state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
}

14. Purity#setBitmap()

Project: cordova-amazon-fireos
File: Purity.java
public void setBitmap(AmazonWebView view) {
    Picture p = view.capturePicture();
    state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
}

15. JavaBrowserViewRendererHelper#recordBitmapIntoPicture()

Project: chromium_webview
File: JavaBrowserViewRendererHelper.java
/**
     * Creates a new Picture that records drawing a provided bitmap.
     * Will return an empty Picture if the Bitmap is null.
     */
@CalledByNative
private static Picture recordBitmapIntoPicture(Bitmap bitmap) {
    Picture picture = new Picture();
    if (bitmap != null) {
        Canvas recordingCanvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight());
        drawBitmapIntoCanvas(bitmap, recordingCanvas, 0, 0);
        picture.endRecording();
    }
    return picture;
}

16. SnapshotHelper#dumpPic()

Project: Cafe
File: SnapshotHelper.java
public static void dumpPic(WebView view, String filename) {
    Picture picture = view.capturePicture();
    print("[picture]width: " + picture.getWidth() + ", height:" + picture.getHeight() + "| [view]width:" + view.getWidth() + ", contentheight:" + view.getContentHeight());
    if (picture.getWidth() == 0 || picture.getHeight() == 0) {
        print("something error!");
        return;
    }
    int width, height;
    //        if (Build.VERSION.SDK_INT < 17) {
    float i = view.getScale();
    print("scale: " + i);
    width = (int) (picture.getWidth() * i);
    height = (int) (picture.getHeight() * i);
    //        } else {
    //            float sx = view.getScaleX();
    //            float sy = view.getScaleY();
    //            print("scaleX: " + sx + "scaleY: " + sy);
    //            width = (int) (picture.getWidth() * sx);
    //            height = (int) (picture.getHeight() * sy);
    //        }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    //picture.draw( c );
    //c.drawPicture(picture);
    view.draw(c);
    outputToFile(filename, bitmap);
}