List of usage examples for android.graphics Canvas getMatrix
@Deprecated public void getMatrix(@NonNull Matrix ctm)
From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java
@Override public void draw(Canvas canvas) { // We will offset the bounds for drawBitmap, so copyBounds() here instead // of getBounds(). copyBounds(mTmpBounds);/*from w w w .ja va2 s . c om*/ if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) { // Nothing to draw return; } // Color filters always override tint filters. final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter); // The imageView can scale the canvas in different ways, in order to // avoid blurry scaling, we have to draw into a bitmap with exact pixel // size first. This bitmap size is determined by the bounds and the // canvas scale. canvas.getMatrix(mTmpMatrix); mTmpMatrix.getValues(mTmpFloats); float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]); float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]); int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX); int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY); scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth); scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight); if (scaledWidth <= 0 || scaledHeight <= 0) { return; } final int saveCount = canvas.save(); canvas.translate(mTmpBounds.left, mTmpBounds.top); // Handle RTL mirroring. final boolean needMirroring = needMirroring(); if (needMirroring) { canvas.translate(mTmpBounds.width(), 0); canvas.scale(-1.0f, 1.0f); } // At this point, canvas has been translated to the right position. // And we use this bound for the destination rect for the drawBitmap, so // we offset to (0, 0); mTmpBounds.offsetTo(0, 0); mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight); if (!mAllowCaching) { mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); } else { if (!mVectorState.canReuseCache()) { mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); mVectorState.updateCacheStates(); } } mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds); canvas.restoreToCount(saveCount); }
From source file:com.hippo.vector.VectorDrawable.java
@Override @SuppressWarnings("deprecation") public void draw(Canvas canvas) { // We will offset the bounds for drawBitmap, so copyBounds() here instead // of getBounds(). copyBounds(mTmpBounds);//w ww .j a va 2 s . c o m if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) { // Nothing to draw return; } // Color filters always override tint filters. final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter); // The imageView can scale the canvas in different ways, in order to // avoid blurry scaling, we have to draw into a bitmap with exact pixel // size first. This bitmap size is determined by the bounds and the // canvas scale. canvas.getMatrix(mTmpMatrix); mTmpMatrix.getValues(mTmpFloats); float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]); float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]); int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX); int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY); scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth); scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight); if (scaledWidth <= 0 || scaledHeight <= 0) { return; } final int saveCount = canvas.save(); canvas.translate(mTmpBounds.left, mTmpBounds.top); // Handle RTL mirroring. final boolean needMirroring = needMirroring(); if (needMirroring) { canvas.translate(mTmpBounds.width(), 0); canvas.scale(-1.0f, 1.0f); } // At this point, canvas has been translated to the right position. // And we use this bound for the destination rect for the drawBitmap, so // we offset to (0, 0); mTmpBounds.offsetTo(0, 0); mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight); if (!mAllowCaching) { mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); } else { if (!mVectorState.canReuseCache()) { mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); mVectorState.updateCacheStates(); } } mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds); canvas.restoreToCount(saveCount); }
From source file:com.pdftron.pdf.tools.Tool.java
public void onDraw(Canvas canvas, android.graphics.Matrix tfm) { // Draw page number if (mShowPageNum && mPageNumberIndicatorVisible) { int width = mPDFView.getWidth(); int height = mPDFView.getHeight(); int page_num = mPDFView.getCurrentPage(); boolean restore = false; float yOffset = 0; try {/*from w w w . jav a 2 s. c o m*/ // During page sliding, PDFViewCtrl might apply extra transformation // matrix to Canvas for animation. However, page number should not // move; hence applying the inverse to offset it. if (!tfm.isIdentity()) { canvas.save(); restore = true; tfm.invert(mTempMtx1); canvas.getMatrix(mTempMtx2); mTempMtx2.postConcat(mTempMtx1); canvas.setMatrix(mTempMtx2); // Workaround for bug found in Android > ICS with hardware acceleration turned // ON. See http://code.google.com/p/android/issues/detail?id=24517 for more info if (Build.VERSION.SDK_INT >= 14 /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ && mPDFView.isHardwareAccelerated()) { Rect rectangle = new Rect(); ((android.app.Activity) mPDFView.getContext()).getWindow().getDecorView() .getWindowVisibleDisplayFrame(rectangle); yOffset = rectangle.top; } } int page_count = mPDFView.getDoc().getPageCount(); String str = String.format(getStringFromResId(R.string.tools_misc_pagerange), page_num, page_count); Rect r = new Rect(); mPaint4PageNum.getTextBounds(str, 0, str.length(), r); float str_width = r.width(); float str_height = r.height(); float margin = str_height / 1.5f; float left = width - str_width * 1.5f - margin + mPDFView.getScrollX(); float top = mPDFView.getScrollY() + height - mPageNumPosAdjust - str_height * 3.0f + yOffset; float right = left + str_width + margin * 2; float bottom = top + str_height + margin * 2; mTempPageDrawingRectF.set(left, top, right, bottom); mPaint4PageNum.setColor( mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_background)); canvas.drawRoundRect(mTempPageDrawingRectF, margin, margin, mPaint4PageNum); mPaint4PageNum .setColor(mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_text)); left += margin; top += str_height / 2 + margin + mPaint4PageNum.descent(); canvas.drawText(str, left, top - 0.5f, mPaint4PageNum); } catch (Exception e) { } finally { if (restore) { canvas.restore(); } } } }
From source file:android.support.graphics.drawable.VectorDrawableCompat.java
@Override public void draw(Canvas canvas) { if (mDelegateDrawable != null) { mDelegateDrawable.draw(canvas);//from ww w.ja va 2 s. com return; } // We will offset the bounds for drawBitmap, so copyBounds() here instead // of getBounds(). copyBounds(mTmpBounds); if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) { // Nothing to draw return; } // Color filters always override tint filters. final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter); // The imageView can scale the canvas in different ways, in order to // avoid blurry scaling, we have to draw into a bitmap with exact pixel // size first. This bitmap size is determined by the bounds and the // canvas scale. canvas.getMatrix(mTmpMatrix); mTmpMatrix.getValues(mTmpFloats); float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]); float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]); float canvasSkewX = Math.abs(mTmpFloats[Matrix.MSKEW_X]); float canvasSkewY = Math.abs(mTmpFloats[Matrix.MSKEW_Y]); // When there is any rotation / skew, then the scale value is not valid. if (canvasSkewX != 0 || canvasSkewY != 0) { canvasScaleX = 1.0f; canvasScaleY = 1.0f; } int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX); int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY); scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth); scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight); if (scaledWidth <= 0 || scaledHeight <= 0) { return; } final int saveCount = canvas.save(); canvas.translate(mTmpBounds.left, mTmpBounds.top); // Handle RTL mirroring. final boolean needMirroring = needMirroring(); if (needMirroring) { canvas.translate(mTmpBounds.width(), 0); canvas.scale(-1.0f, 1.0f); } // At this point, canvas has been translated to the right position. // And we use this bound for the destination rect for the drawBitmap, so // we offset to (0, 0); mTmpBounds.offsetTo(0, 0); mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight); if (!mAllowCaching) { mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); } else { if (!mVectorState.canReuseCache()) { mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); mVectorState.updateCacheStates(); } } mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds); canvas.restoreToCount(saveCount); }