/** * 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; }
@Override public void onDraw(Canvas canvas) { // zooming animation if (scalingInterpolator.isActive()) { setCurrentScaling(scalingInterpolator.getCurrentValue()); } // translation animation if (translationXInterpolator.isActive() || translationYInterpolator.isActive()) { float transX = currentTranslation[0]; float transY = currentTranslation[1]; if (translationXInterpolator.isActive()) { transX = translationXInterpolator.getCurrentValue(); } if (translationYInterpolator.isActive()) { transY = translationYInterpolator.getCurrentValue(); } setCurrentTranslation(transX, transY); } // center rotation animation if (centerRotationInterpolator.isActive()) { setCurrentCenterRotation(centerRotationInterpolator.getCurrentValue()); } // calculate current viewport matrix if necessary if (getAndClearViewportFlag()) { recalculateViewportTransformation(); recalculateSizeScale(); } // clear background canvas.drawColor(0xFF000000); // draw audio scene canvas.setMatrix(viewportTransformation); synchronized (GlobalData.audioScene) { GlobalData.audioScene.draw(canvas, currentInverseScaling); } // reset matrix canvas.setMatrix(null); // draw size scale sizeScalePicture.draw(canvas); }
@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; }
public void captureRandCodePic(int randcodex, int randcodey) { try { Picture pic = wv.capturePicture(); Bitmap bmp = Bitmap.createBitmap(pic.getWidth(), pic.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bmp); pic.draw(canvas); Bitmap code = Bitmap.createBitmap(293, 190, Config.ARGB_8888); Canvas canCode = new Canvas(code); canCode.drawBitmap( bmp, new Rect( randcodex * rate, randcodey * rate, randcodex * rate + 293 * rate, randcodey * rate + 190 * rate), new Rect(0, 0, 293, 190), null); BitmapUtils.savePicture( code, Environment.getExternalStorageDirectory().getAbsolutePath(), "capture.bmp"); } catch (Exception e) { } }
/** * Create a screen shot for the current view. * * @return A bitmap of the screen shot. */ private Bitmap createScreenshot() { Picture thumbnail = mWebView.capturePicture(); if (thumbnail == null) { return null; } float density = mContext.getResources().getDisplayMetrics().density; int thumbnailWidth = (int) (Constants.BOOKMARK_THUMBNAIL_WIDTH_FACTOR * density); int thumbnailHeight = (int) (Constants.BOOKMARK_THUMBNAIL_HEIGHT_FACTOR * density); Bitmap bm = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bm); if (thumbnail.getWidth() > 0) { float scaleFactor = (float) thumbnailWidth / (float) thumbnail.getWidth(); canvas.scale(scaleFactor, scaleFactor); } thumbnail.draw(canvas); return bm; }