Matrix isIdentity - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Matrix isIdentity method.

This code example shows how to use the following methods:isIdentity, mapRect, rectStaysRect
        // Re-implement Bitmap createBitmap() to always return a mutable bitmap. 
        Canvas canvas = new Canvas();
 
        Bitmap bitmap;
        Paint paint;
        if ((m == null) || m.isIdentity()) {
            bitmap = Bitmap.createBitmap(width, height, source.getConfig());
            paint = null;
        } else { 
            RectF rect = new RectF(0, 0, width, height);
            m.mapRect(rect);
            bitmap = Bitmap.createBitmap(
                    Math.round(rect.width()), Math.round(rect.height()), source.getConfig());
 
            canvas.translate(-rect.left, -rect.top);
            canvas.concat(m);
 
            paint = new Paint(Paint.FILTER_BITMAP_FLAG);
            if (!m.rectStaysRect()) {
                paint.setAntiAlias(true);

7
CodeRank
This code example shows how to use the following methods:isIdentity
    return newBitmap;
  } 
 
  @Implementation 
  public static Bitmap createBitmap(Bitmap src, int x, int y, int width, int height, Matrix matrix, boolean filter) {
    if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight() && (matrix == null || matrix.isIdentity())) {
      return src; // Return the original.
    } 
 
    Bitmap newBitmap = Robolectric.newInstanceOf(Bitmap.class);
    ShadowBitmap shadowBitmap = shadowOf(newBitmap);
 
    shadowBitmap.appendDescription(shadowOf(src).getDescription());
    shadowBitmap.appendDescription(" at (" + x + "," + y);
    shadowBitmap.appendDescription(" with width " + width + " and height " + height);
    if (matrix != null) {
      shadowBitmap.appendDescription(" using matrix " + matrix);
    } 
    if (filter) {
      shadowBitmap.appendDescription(" with filter");
6
CodeRank
This code example shows how to use the following methods:isIdentity, postTranslate, setRectToRect, setScale, setTranslate
      // use its native size. 
      mDrawable.setBounds(0, 0, dwidth, dheight);
 
      if (ScaleType.MATRIX == mScaleType) {
        // Use the specified matrix as-is. 
        if (mMatrix.isIdentity()) {
          mDrawMatrix = null;
        } else { 
          mDrawMatrix = mMatrix;
        } 
      } else if (fits) {
        // The bitmap fits exactly, no transform needed. 
        mDrawMatrix = null;
      } else if (ScaleType.CENTER == mScaleType) {
        // Center bitmap in view, no scaling. 
        mDrawMatrix = mMatrix;
        mDrawMatrix.setTranslate((int) ((vwidth - dwidth) * half + half),
            (int) ((vheight - dheight) * half + half));
      } else if (ScaleType.CENTER_CROP == mScaleType) {
        mDrawMatrix = mMatrix;

6
CodeRank
This code example shows how to use the following methods:isIdentity
 
  @Override 
  protected void dispatchDraw(Canvas canvas) {
    final int saveCount = canvas.save();
    final Matrix m = mController.getEffectsMatrix();
    if (!m.isIdentity())
      canvas.concat(m);
 
    final float alpha = mController.getEffectsAlpha();
    if (alpha != 1f)
      canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int)(255 * alpha), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
 
    super.dispatchDraw(canvas);
 
    final int fadeFactor = mController.getFadeFactor();
    if (fadeFactor > 0) {
      mFadePaint.setColor(Color.argb(fadeFactor, 0, 0, 0));
      canvas.drawRect(0, 0, getWidth(), getHeight(), mFadePaint);
    } 
 
6
CodeRank
This code example shows how to use the following methods:createBitmap, isIdentity, postRotate
        final int imageHeight = bitmap.getHeight();
 
        final float widthScaleRatio = reqWidth / (float) imageWidth;
        final float heightScaleRatio = reqHeight / (float) imageHeight;
        final float scaleRatio = Math.min(widthScaleRatio, heightScaleRatio);
        final Matrix matrix = new Matrix();
        matrix.postRotate(scaleRatio);
 
        if (!matrix.isIdentity()) {
            return bitmap.createBitmap(bitmap, 0, 0, imageWidth, imageHeight, matrix, true);
        } else { 
            return bitmap;
        } 
    } 
 
    public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;
 
6
CodeRank
This code example shows how to use the following methods:createBitmap, isIdentity, postRotate, postTranslate, setScale
            BitmapFactory.Options sampleOpt = new BitmapFactory.Options();
            sampleOpt.inSampleSize = opt.inSampleSize;
 
            bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), sampleOpt);
 
            Matrix m = new Matrix();
            float scale;
            float dx = 0, dy = 0;
 
            // assumes height and width are the same 
            if (bitmap.getWidth() > bitmap.getHeight()) {
                scale = (float) minHeight / (float) bitmap.getHeight();
                dx = (minWidth - bitmap.getWidth() * scale) * 0.5f;
            } else { 
                scale = (float) minWidth / (float) bitmap.getWidth();
                dy = (minHeight - bitmap.getHeight() * scale) * 0.5f;
            } 
 
            m.setScale(scale, scale);
            m.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));

6
CodeRank
This code example shows how to use the following methods:isIdentity, mapRect, rectStaysRect
        // Re-implement Bitmap createBitmap() to always return a mutable bitmap. 
        Canvas canvas = new Canvas();
 
        Bitmap bitmap;
        Paint paint;
        if ((m == null) || m.isIdentity()) {
            bitmap = Bitmap.createBitmap(width, height, source.getConfig());
            paint = null;
        } else { 
            RectF rect = new RectF(0, 0, width, height);
            m.mapRect(rect);
            bitmap = Bitmap.createBitmap(
                    Math.round(rect.width()), Math.round(rect.height()), source.getConfig());
 
            canvas.translate(-rect.left, -rect.top);
            canvas.concat(m);
 
            paint = new Paint(Paint.FILTER_BITMAP_FLAG);
            if (!m.rectStaysRect()) {
                paint.setAntiAlias(true);

5
CodeRank
This code example shows how to use the following methods:isIdentity, mapPoints, postConcat, set
		} 
	} 
 
	// Translate a given point through a given matrix. 
	static private void translatePoint(Matrix matrix, float[] xy) {
		matrix.mapPoints(xy);
	} 
 
	// Identical to the setImageMatrix method in ImageView 
	public void setImageMatrix(Matrix m) {
		if (m != null && m.isIdentity()) {
			m = null;
		} 
 
		// don't invalidate unless we're actually changing our matrix 
		if (m == null && !this.mMatrix.isIdentity() || m != null
				&& !this.mMatrix.equals(m)) {
			this.mMatrix.set(m);
			invalidate();
		} 

5
CodeRank
This code example shows how to use the following methods:isIdentity, mapRect
        Bitmap bitmap;
 
        final Rect from = new Rect(x, y, x + width, y + height);
        final RectF to = new RectF(0, 0, width, height);
 
        if (m == null || m.isIdentity()) {
            bitmap = Bitmap.createBitmap(scaledWidth + (int) offset,
                    scaledHeight + (int) (clipShadow ? (offset / 2.0f) : offset),
                    Bitmap.Config.ARGB_8888);
            paint = null;
        } else { 
            RectF mapped = new RectF();
            m.mapRect(mapped, to);
 
            scaledWidth = Math.round(mapped.width());
            scaledHeight = Math.round(mapped.height());
 
            bitmap = Bitmap.createBitmap(scaledWidth + (int) offset,
                    scaledHeight + (int) (clipShadow ? (offset / 2.0f) : offset),
                    Bitmap.Config.ARGB_8888);
4
CodeRank
isIdentity Method Overview
Returns true if the matrix is identity.
See Code Examples for other Android Matrix Methods: