Java Code Examples for android.graphics.Picture#endRecording()
The following examples show how to use
android.graphics.Picture#endRecording() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppTransition.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Creates an overlay with a background color and a thumbnail for the cross profile apps * animation. */ GraphicBuffer createCrossProfileAppsThumbnail( @DrawableRes int thumbnailDrawableRes, Rect frame) { final int width = frame.width(); final int height = frame.height(); final Picture picture = new Picture(); final Canvas canvas = picture.beginRecording(width, height); canvas.drawColor(Color.argb(0.6f, 0, 0, 0)); final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize( com.android.internal.R.dimen.cross_profile_apps_thumbnail_size); final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes); drawable.setBounds( (width - thumbnailSize) / 2, (height - thumbnailSize) / 2, (width + thumbnailSize) / 2, (height + thumbnailSize) / 2); drawable.setTint(mContext.getColor(android.R.color.white)); drawable.draw(canvas); picture.endRecording(); return Bitmap.createBitmap(picture).createGraphicBufferHandle(); }
Example 2
Source File: SVG.java From microMathematics with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"WeakerAccess", "unused"}) public Picture renderToPicture(int widthInPixels, int heightInPixels, RenderOptions renderOptions) { Picture picture = new Picture(); Canvas canvas = picture.beginRecording(widthInPixels, heightInPixels); if (renderOptions == null || renderOptions.viewPort == null) { renderOptions = (renderOptions == null) ? new RenderOptions() : new RenderOptions(renderOptions); renderOptions.viewPort(0f, 0f, (float) widthInPixels, (float) heightInPixels); } SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, this.renderDPI); renderer.renderDocument(this, renderOptions); picture.endRecording(); return picture; }
Example 3
Source File: SVG.java From microMathematics with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"WeakerAccess", "unused"}) public Picture renderViewToPicture(String viewId, int widthInPixels, int heightInPixels) { RenderOptions renderOptions = new RenderOptions(); renderOptions.view(viewId) .viewPort(0f, 0f, (float) widthInPixels, (float) heightInPixels); Picture picture = new Picture(); Canvas canvas = picture.beginRecording(widthInPixels, heightInPixels); SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, this.renderDPI); renderer.renderDocument(this, renderOptions); picture.endRecording(); return picture; }
Example 4
Source File: SVG.java From XDroidAnimation with Apache License 2.0 | 6 votes |
/** * 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; }
Example 5
Source File: RecordingCanvas.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public final void drawPicture(@NonNull Picture picture) { picture.endRecording(); int restoreCount = save(); picture.draw(this); restoreToCount(restoreCount); }
Example 6
Source File: TransitionUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Get a copy of bitmap of given drawable, return null if intrinsic size is zero */ public static Bitmap createDrawableBitmap(Drawable drawable, View hostView) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); if (width <= 0 || height <= 0) { return null; } float scale = Math.min(1f, ((float)MAX_IMAGE_SIZE) / (width * height)); if (drawable instanceof BitmapDrawable && scale == 1f) { // return same bitmap if scale down not needed return ((BitmapDrawable) drawable).getBitmap(); } int bitmapWidth = (int) (width * scale); int bitmapHeight = (int) (height * scale); final Picture picture = new Picture(); final Canvas canvas = picture.beginRecording(width, height); // Do stuff with the canvas Rect existingBounds = drawable.getBounds(); int left = existingBounds.left; int top = existingBounds.top; int right = existingBounds.right; int bottom = existingBounds.bottom; drawable.setBounds(0, 0, bitmapWidth, bitmapHeight); drawable.draw(canvas); drawable.setBounds(left, top, right, bottom); picture.endRecording(); return Bitmap.createBitmap(picture); }
Example 7
Source File: SVG.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example 8
Source File: SVG.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example 9
Source File: MapUtils.java From MapView with MIT License | 5 votes |
/** * 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; }
Example 10
Source File: SVG.java From XDroidAnimation with Apache License 2.0 | 5 votes |
/** * 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; }
Example 11
Source File: PXShapeView.java From pixate-freestyle-android with Apache License 2.0 | 5 votes |
public Picture renderToImage(Rect bounds) { if (document != null) { Picture image = new Picture(); try { Canvas c = image.beginRecording(bounds.width(), bounds.height()); document.render(c); } catch (Exception ioe) { PXLog.e(TAG, ioe, "Error rendering to image"); } finally { image.endRecording(); } return image; } return null; }
Example 12
Source File: JavaBrowserViewRendererHelper.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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; }
Example 13
Source File: JavaBrowserViewRendererHelper.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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; }
Example 14
Source File: NativeOpenStreetMapController.java From appinventor-extensions with Apache License 2.0 | 4 votes |
private Drawable rasterizeSVG(MapMarker aiMarker, SVG markerSvg) { SVG.Svg svg = markerSvg.getRootElement(); final float density = view.getContext().getResources().getDisplayMetrics().density; float height = aiMarker.Height() <= 0 ? getBestGuessHeight(svg) : aiMarker.Height(); float width = aiMarker.Width() <= 0 ? getBestGuessWidth(svg) : aiMarker.Width(); float scaleH = height / getBestGuessHeight(svg); float scaleW = width / getBestGuessWidth(svg); float scale = (float) Math.sqrt(scaleH * scaleH + scaleW * scaleW); // update fill color of SVG <path> Paint fillPaint = new Paint(); Paint strokePaint = new Paint(); PaintUtil.changePaint(fillPaint, aiMarker.FillColor()); PaintUtil.changePaint(strokePaint, aiMarker.StrokeColor()); SVG.Length strokeWidth = new SVG.Length(aiMarker.StrokeWidth() / scale); for (SVG.SvgObject element : svg.getChildren()) { if (element instanceof SVG.SvgConditionalElement) { SVG.SvgConditionalElement path = (SVG.SvgConditionalElement) element; path.baseStyle.fill = new SVG.Colour(fillPaint.getColor()); path.baseStyle.fillOpacity = fillPaint.getAlpha()/255.0f; path.baseStyle.stroke = new SVG.Colour(strokePaint.getColor()); path.baseStyle.strokeOpacity = strokePaint.getAlpha()/255.0f; path.baseStyle.strokeWidth = strokeWidth; path.baseStyle.specifiedFlags = 0x3d; if (path.style != null) { if ((path.style.specifiedFlags & SPECIFIED_FILL) == 0) { path.style.fill = new SVG.Colour(fillPaint.getColor()); path.style.specifiedFlags |= SPECIFIED_FILL; } if ((path.style.specifiedFlags & SPECIFIED_FILL_OPACITY) == 0) { path.style.fillOpacity = fillPaint.getAlpha()/255.0f; path.style.specifiedFlags |= SPECIFIED_FILL_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE) == 0) { path.style.stroke = new SVG.Colour(strokePaint.getColor()); path.style.specifiedFlags |= SPECIFIED_STROKE; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_OPACITY) == 0) { path.style.strokeOpacity = strokePaint.getAlpha()/255.0f; path.style.specifiedFlags |= SPECIFIED_STROKE_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_WIDTH) == 0) { path.style.strokeWidth = strokeWidth; path.style.specifiedFlags |= SPECIFIED_STROKE_WIDTH; } } } } // draw SVG to Picture and create a BitmapDrawable for rendering Picture picture = markerSvg.renderToPicture(); Picture scaledPicture = new Picture(); Canvas canvas = scaledPicture.beginRecording((int)((width + 2.0f * aiMarker.StrokeWidth()) * density), (int)((height + 2.0f * aiMarker.StrokeWidth()) * density)); canvas.scale(density * scaleW, density * scaleH); canvas.translate(strokeWidth.floatValue(), strokeWidth.floatValue()); picture.draw(canvas); scaledPicture.endRecording(); return new PictureDrawable(scaledPicture); }