Java Code Examples for android.graphics.Picture#draw()
The following examples show how to use
android.graphics.Picture#draw() .
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: 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 2
Source File: PictureBitmapTextureAtlasSource.java From 30-android-libraries-in-30-days with Apache License 2.0 | 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 3
Source File: PlayPauseDrawable.java From PlayPauseDrawable with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { canvas.drawCircle(mBounds.centerX(), mBounds.centerY(), mBounds.centerX(), mBackgroundPaint); Picture picture = new Picture() ; picture.draw(canvas); canvas.save(); canvas.rotate(180 * mRotation, (x(0) + x(1))/2, (y(0) + y(1))/2); canvas.drawLine(x(0), y(0), x(1), y(1), mLinePaint); canvas.restore(); canvas.save(); canvas.rotate(180 * mRotation, (x(2) + x(3)) / 2, (y(2) + y(3)) / 2); canvas.drawLine(x(2), y(2), x(3), y(3), mLinePaint); canvas.restore(); canvas.save(); canvas.rotate(180 * mRotation, (x(4) + x(5)) / 2, (y(4) + y(5)) / 2); canvas.drawLine(x(4), y(4), x(5), y(5), mLinePaint); canvas.restore(); }
Example 4
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 5
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 6
Source File: AllWebViewActivity.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { switch (v.getId()) { case R.id.button: String time = Tools.getCurrentTime(); String version = Tools.getAppVersion(mContext); String name = Tools.getName(mContext); String currentUrl = mWebView.getUrl(); String info = "Application Info: \n\n version: " + version + "\n name: " + name + "\n curTime: " + time + "\n curUrl: " + currentUrl; mWebView.loadUrl("javascript:showAlert('" + info + "')"); break; case R.id.save: Picture snapShot = mWebView.capturePicture(); Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); snapShot.draw(canvas); if (!TextUtils.isEmpty(FileUtil.savaBitmap2SDcard(mContext, bmp, "1111"))) { TT.showSToast(mContext, "success"); } break; default: break; } }
Example 7
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 8
Source File: ScreenShoot.java From Utils with Apache License 2.0 | 5 votes |
/** * shoot the web view */ public static Bitmap shoot(WebView webView) { Picture snapShot = webView.capturePicture(); Bitmap bitmap = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); snapShot.draw(canvas); return bitmap; }
Example 9
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 10
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 11
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 12
Source File: X5WebUtils.java From YCWebView with Apache License 2.0 | 5 votes |
/** * Android5.0以下版本 * 对WebView进行截屏,虽然使用过期方法, * 但在当前Android版本中测试可行 * @param webView WebView控件 * @return 返回bitmap对象 */ public static Bitmap captureWebViewKitKat(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.RGB_565); Canvas canvas = new Canvas(bitmap); picture.draw(canvas); return bitmap; } return null; }
Example 13
Source File: ScreenshotTaker.java From AndroidRipper with GNU Affero General Public License v3.0 | 5 votes |
/** * 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; }
Example 14
Source File: HelpDraw.java From DS4Android with MIT License | 5 votes |
/** * 绘制picture * * @param canvas * @param pictures */ public static void draw(Canvas canvas, Picture... pictures) { if (!isDraw) { return; } for (Picture picture : pictures) { picture.draw(canvas); } }
Example 15
Source File: ScreenShotHelper.java From OmniList with GNU Affero General Public License v3.0 | 5 votes |
private static Bitmap createType1(WebView webView, FileHelper.OnSavedToGalleryListener listener) { Picture picture = webView.capturePicture(); int width = picture.getWidth(); int height = picture.getHeight(); Bitmap bitmap = null; if (width > 0 && height > 0) { bitmap = Bitmap.createBitmap(width, height, Config.RGB_565); Canvas canvas = new Canvas(bitmap); picture.draw(canvas); } return bitmap; }
Example 16
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 17
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 18
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); }