android.graphics.Picture Java Examples
The following examples show how to use
android.graphics.Picture.
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: Purity.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
public boolean checkRenderView(AmazonWebView view) { if(state == null) { setBitmap(view); return false; } else { Picture p = view.capturePicture(); Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888); boolean result = newState.equals(state); newState.recycle(); return result; } }
Example #2
Source File: X5WebUtils.java From YCWebView with Apache License 2.0 | 6 votes |
/** * X5内核截取长图【暂时用不了】 * @param webView x5WebView的控件 * @return 返回bitmap对象 * * 方法 * 1. 使用X5内核方法snapshotWholePage(Canvas, boolean, boolean);在X5内核中提供了一个截取整个 * WebView界面的方法snapshotWholePage(Canvas, boolean, boolean),但是这个方法有个缺点, * 就是不以屏幕上WebView的宽高截图,只是以WebView的contentWidth和contentHeight为宽高截图, * 所以截出来的图片会不怎么清晰,但作为缩略图效果还是不错了。 * 2. 使用capturePicture()截取清晰长图;如果想要在X5内核下截到清晰的长图,不能使用 * snapshotWholePage(),依然可以采用capturePicture()。X5内核下使用capturePicture()进行截图, * 可以直接拿到WebView的清晰长图,但这是个Deprecated的方法,使用的时候要做好异常处理。 */ @Deprecated public static Bitmap captureX5Picture(WebView webView) { if (webView == null) { return null; } try { Picture picture = webView.capturePicture(); int width = picture.getWidth(); int height = picture.getHeight(); if (width > 0 && height > 0) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); picture.draw(canvas); return bitmap; } } catch (Exception e){ e.printStackTrace(); return null; } return null; }
Example #3
Source File: AwContents.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Enable the onNewPicture callback. * @param enabled Flag to enable the callback. * @param invalidationOnly Flag to call back only on invalidation without providing a picture. */ public void enableOnNewPicture(boolean enabled, boolean invalidationOnly) { if (mNativeAwContents == 0) return; if (invalidationOnly) { mPictureListenerContentProvider = null; } else if (enabled && mPictureListenerContentProvider == null) { mPictureListenerContentProvider = new Callable<Picture>() { @Override public Picture call() { return capturePicture(); } }; } mPictureListenerEnabled = enabled; syncOnNewPictureStateToNative(); }
Example #4
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 #5
Source File: ReactWebViewManager.java From react-native-GPay with MIT License | 6 votes |
protected WebView.PictureListener getPictureListener() { if (mPictureListener == null) { mPictureListener = new WebView.PictureListener() { @Override public void onNewPicture(WebView webView, Picture picture) { dispatchEvent( webView, new ContentSizeChangeEvent( webView.getId(), webView.getWidth(), webView.getContentHeight())); } }; } return mPictureListener; }
Example #6
Source File: Web3WebviewManager.java From react-native-web3-webview with MIT License | 6 votes |
protected WebView.PictureListener getPictureListener() { if (mPictureListener == null) { mPictureListener = new WebView.PictureListener() { @Override public void onNewPicture(WebView webView, Picture picture) { dispatchEvent( webView, new ContentSizeChangeEvent( webView.getId(), webView.getWidth(), webView.getContentHeight())); } }; } return mPictureListener; }
Example #7
Source File: HelpDraw.java From DS4Android with MIT License | 6 votes |
/** * 绘制坐标系 * * @param coo 坐标系原点 * @param winSize 屏幕尺寸 * @param winSize 屏幕尺寸 */ private static Picture getCoo(Point coo, Point winSize, boolean showText) { Picture picture = new Picture(); Canvas recording = picture.beginRecording(winSize.x, winSize.y); //初始化网格画笔 Paint paint = new Paint(); paint.setStrokeWidth(3); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); //设置虚线效果new float[]{可见长度, 不可见长度},偏移值 paint.setPathEffect(null); //绘制直线 recording.drawPath(HelpPath.cooPath(coo, winSize), paint); //左箭头 recording.drawLine(winSize.x, coo.y, winSize.x - 40, coo.y - 20, paint); recording.drawLine(winSize.x, coo.y, winSize.x - 40, coo.y + 20, paint); //下箭头 recording.drawLine(coo.x, winSize.y, coo.x - 20, winSize.y - 40, paint); recording.drawLine(coo.x, winSize.y, coo.x + 20, winSize.y - 40, paint); //为坐标系绘制文字 if (showText) { drawText4Coo(recording, coo, winSize, paint); } return picture; }
Example #8
Source File: SVGParser.java From CustomShapeImageView with Apache License 2.0 | 6 votes |
private static SVG parse(InputStream in, Integer searchColor, Integer replaceColor, boolean whiteMode, int targetWidth, int targetHeight) throws SVGParseException { // Util.debug("Parsing SVG..."); try { long start = System.currentTimeMillis(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); final Picture picture = new Picture(); SVGHandler handler = new SVGHandler(picture, targetWidth, targetHeight); handler.setColorSwap(searchColor, replaceColor); handler.setWhiteMode(whiteMode); xr.setContentHandler(handler); xr.parse(new InputSource(in)); // Util.debug("Parsing complete in " + (System.currentTimeMillis() - start) + " millis."); SVG result = new SVG(picture, handler.bounds); // Skip bounds if it was an empty pic if (!Float.isInfinite(handler.limits.top)) { result.setLimits(handler.limits); } return result; } catch (Exception e) { throw new SVGParseException(e); } }
Example #9
Source File: RNX5WebViewManager.java From react-native-x5 with MIT License | 6 votes |
private WebView.PictureListener getPictureListener() { if (mPictureListener == null) { mPictureListener = new WebView.PictureListener() { @Override public void onNewPicture(WebView webView, Picture picture) { dispatchEvent( webView, new ContentSizeChangeEvent( webView.getId(), webView.getWidth(), webView.getContentHeight())); } }; } return mPictureListener; }
Example #10
Source File: DetailFragment.java From iZhihu with GNU General Public License v2.0 | 6 votes |
/** * 截取所有网页内容到 Bitmap * * @return Bitmap */ Bitmap genCaptureBitmap() throws OutOfMemoryError { // @todo Future versions of WebView may not support use on other threads. try { Picture picture = getWebView().capturePicture(); int height = picture.getHeight(), width = picture.getWidth(); if (height == 0 || width == 0) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); picture.draw(canvas); return bitmap; } catch (NullPointerException e) { return null; } }
Example #11
Source File: MapLayer.java From MapView with MIT License | 6 votes |
public void setImage(Picture image) { this.image = image; if (mapView.getWidth() == 0) { ViewTreeObserver vto = mapView.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { if (!hasMeasured) { initMapLayer(); hasMeasured = true; } return true; } }); } else { initMapLayer(); } }
Example #12
Source File: SVGParser.java From PdDroidPublisher with GNU General Public License v3.0 | 6 votes |
private static SVG parse(InputStream in, Integer searchColor, Integer replaceColor, boolean whiteMode) throws SVGParseException { // Util.debug("Parsing SVG..."); try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); final Picture picture = new Picture(); SVGHandler handler = new SVGHandler(picture); handler.setColorSwap(searchColor, replaceColor); handler.setWhiteMode(whiteMode); xr.setContentHandler(handler); xr.parse(new InputSource(in)); // Util.debug("Parsing complete in " + (System.currentTimeMillis() - start) + " millis."); SVG result = new SVG(picture, handler.bounds); // Skip bounds if it was an empty pic if (!Float.isInfinite(handler.limits.top)) { result.setLimits(handler.limits); } return result; } catch (Exception e) { throw new SVGParseException(e); } }
Example #13
Source File: AndroidSvgBitmap.java From trekarta with GNU General Public License v3.0 | 6 votes |
public static android.graphics.Bitmap getResourceBitmap(InputStream inputStream, float scaleFactor, float defaultSize, int width, int height, int percent, int color) throws IOException { try { SVG svg = SVG.getFromInputStream(inputStream); Picture picture; if (color != 0) { RenderOptions renderOpts = RenderOptions.create().css("* { fill: #" + String.format("%06x", color & 0x00ffffff) + "; }"); picture = svg.renderToPicture(renderOpts); } else { picture = svg.renderToPicture(); } double scale = scaleFactor / Math.sqrt((picture.getHeight() * picture.getWidth()) / defaultSize); float[] bmpSize = GraphicUtils.imageSize(picture.getWidth(), picture.getHeight(), (float) scale, width, height, percent); android.graphics.Bitmap bitmap = android.graphics.Bitmap.createBitmap((int) Math.ceil(bmpSize[0]), (int) Math.ceil(bmpSize[1]), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(picture, new RectF(0, 0, bmpSize[0], bmpSize[1])); return bitmap; } catch (Exception e) { throw new IOException(e); } }
Example #14
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 #15
Source File: PictureBitmapTextureAtlasSource.java From tilt-game-android with MIT License | 6 votes |
@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; }
Example #16
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 #17
Source File: Purity.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
public boolean checkRenderView(WebView view) { if(state == null) { setBitmap(view); return false; } else { Picture p = view.capturePicture(); Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888); boolean result = newState.equals(state); newState.recycle(); return result; } }
Example #18
Source File: PXImagePaint.java From pixate-freestyle-android with Apache License 2.0 | 6 votes |
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(); }
Example #19
Source File: ViewUtils.java From microMathematics with GNU General Public License v3.0 | 5 votes |
public static Bitmap pictureToBitmap(final Picture picture, final int w, final int h) { final PictureDrawable pd = new PictureDrawable(picture); final Bitmap bitmap = Bitmap.createBitmap(w, h, getBitmapConfig()); final Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pd.getPicture()); return bitmap; }
Example #20
Source File: SvgDrawableTranscoder.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
@Override public Resource<PictureDrawable> transcode(Resource<SVG> toTranscode) { SVG svg = toTranscode.get(); Picture picture = svg.renderToPicture(); PictureDrawable drawable = new PictureDrawable(picture); return new SimpleResource<PictureDrawable>(drawable); }
Example #21
Source File: PictureMergeManager.java From kAndroid with Apache License 2.0 | 5 votes |
/** * 对WebView进行截图 * * @param webView * @return */ private Bitmap captureWebView1(WebView webView) { Picture snapShot = webView.capturePicture(); Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); snapShot.draw(canvas); return bmp; }
Example #22
Source File: WebViewCapture.java From ViewCapture with Apache License 2.0 | 5 votes |
private Bitmap captureWebView(WebView webView) { Picture picture = webView.capturePicture(); int width = picture.getWidth(); int height = picture.getHeight(); if (width > 0 && height > 0) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); picture.draw(canvas); return bitmap; } return null; }
Example #23
Source File: PreviewActivity.java From writeily-pro with MIT License | 5 votes |
private Bitmap getBitmapFromWebView(WebView webView) { try { float scale = 1.0f / getResources().getDisplayMetrics().density; Picture picture = webView.capturePicture(); Bitmap bitmap = Bitmap.createBitmap((int) (picture.getWidth() * scale), (int) (picture.getHeight() * scale), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(scale, scale); picture.draw(canvas); return bitmap; } catch (Exception e) { e.printStackTrace(); return null; } }
Example #24
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 #25
Source File: PdDroidPatchView.java From PdDroidPublisher with GNU General Public License v3.0 | 5 votes |
private static Bitmap picture2Bitmap(Picture picture){ PictureDrawable pictureDrawable = new PictureDrawable(picture); Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); //Log.e(TAG, "picture size: " + pictureDrawable.getIntrinsicWidth() + " " + pictureDrawable.getIntrinsicHeight()); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); return bitmap; }
Example #26
Source File: FakeWebView.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public Bitmap getScreenView(){ Picture snapShot = webView.capturePicture(); Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); snapShot.draw(canvas); return bmp; }
Example #27
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 #28
Source File: ScreenUtils.java From BaseProject with Apache License 2.0 | 5 votes |
private static Bitmap captureWebView(WebView webView) { Picture snapShot = webView.capturePicture(); if (snapShot == null) { return null; } Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); snapShot.draw(canvas); return bmp; }
Example #29
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 #30
Source File: MapView.java From MapView with MIT License | 5 votes |
/** * load map image * * @param picture */ public void loadMap(final Picture picture) { isMapLoadFinish = false; new Thread(new Runnable() { @Override public void run() { if (picture != null) { if (mapLayer == null) { mapLayer = new MapLayer(MapView.this); // add map image layer layers.add(mapLayer); } mapLayer.setImage(picture); if (mapViewListener != null) { // load map success, and callback mapViewListener.onMapLoadSuccess(); } isMapLoadFinish = true; refresh(); } else { if (mapViewListener != null) { mapViewListener.onMapLoadFail(); } } } }).start(); }