android.graphics.Matrix.ScaleToFit Java Examples

The following examples show how to use android.graphics.Matrix.ScaleToFit. 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: AutoFitTextureView.java    From pixelvisualcorecamera with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the necessary {@link Matrix} transformation.
 * This method should be called after the camera preview size is determined.
 *
 * @param displayRotation current rotation of default display
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
void configureTransform(
    int displayRotation, int viewWidth, int viewHeight, Size previewSize) {
  Matrix matrix = new Matrix();
  RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  float centerX = viewRect.centerX();
  float centerY = viewRect.centerY();
  if (Surface.ROTATION_90 == displayRotation || Surface.ROTATION_270 == displayRotation) {
    bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
    matrix.setRectToRect(viewRect, bufferRect, ScaleToFit.FILL);
    float scale = Math.max(
        (float) viewHeight / previewSize.getHeight(),
        (float) viewWidth / previewSize.getWidth());
    matrix.postScale(scale, scale, centerX, centerY);
    matrix.postRotate(90 * (displayRotation - 2), centerX, centerY);
  } else if (Surface.ROTATION_180 == displayRotation) {
    matrix.postRotate(180, centerX, centerY);
  }
  setTransform(matrix);
}
 
Example #2
Source File: FloatingActionButtonImpl.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void calculateImageMatrixFromScale(float scale, @NonNull Matrix matrix) {
  matrix.reset();

  Drawable drawable = view.getDrawable();
  if (drawable != null && maxImageSize != 0) {
    // First make sure our image respects mMaxImageSize.
    RectF drawableBounds = tmpRectF1;
    RectF imageBounds = tmpRectF2;
    drawableBounds.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    imageBounds.set(0, 0, maxImageSize, maxImageSize);
    matrix.setRectToRect(drawableBounds, imageBounds, ScaleToFit.CENTER);

    // Then scale it as requested.
    matrix.postScale(scale, scale, maxImageSize / 2f, maxImageSize / 2f);
  }
}
 
Example #3
Source File: ScannerView.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public void setFraming(final Rect frame, final RectF framePreview, final int displayRotation,
        final int cameraRotation, final boolean cameraFlip) {
    this.frame = frame;
    matrix.setRectToRect(framePreview, new RectF(frame), ScaleToFit.FILL);
    matrix.postRotate(-displayRotation, frame.exactCenterX(), frame.exactCenterY());
    matrix.postScale(cameraFlip ? -1 : 1, 1, frame.exactCenterX(), frame.exactCenterY());
    matrix.postRotate(cameraRotation, frame.exactCenterX(), frame.exactCenterY());

    invalidate();
}
 
Example #4
Source File: RoundedBitmapDisplayer.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    this.mRect.set((float) this.margin, (float) this.margin, (float) (bounds.width() - this.margin), (float) (bounds.height() - this.margin));
    Matrix shaderMatrix = new Matrix();
    shaderMatrix.setRectToRect(this.mBitmapRect, this.mRect, ScaleToFit.FILL);
    this.bitmapShader.setLocalMatrix(shaderMatrix);
}
 
Example #5
Source File: ScannerView.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public void setFraming(final Rect frame, final RectF framePreview, final int displayRotation,
                       final int cameraRotation, final boolean cameraFlip) {
    this.frame = frame;
    matrix.setRectToRect(framePreview, new RectF(frame), ScaleToFit.FILL);
    matrix.postRotate(-displayRotation, frame.exactCenterX(), frame.exactCenterY());
    matrix.postScale(cameraFlip ? -1 : 1, 1, frame.exactCenterX(), frame.exactCenterY());
    matrix.postRotate(cameraRotation, frame.exactCenterX(), frame.exactCenterY());

    invalidate();
}
 
Example #6
Source File: ScannerView.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void setFraming(final Rect frame, final RectF framePreview, final int displayRotation,
        final int cameraRotation, final boolean cameraFlip) {
    this.frame = frame;
    matrix.setRectToRect(framePreview, new RectF(frame), ScaleToFit.FILL);
    matrix.postRotate(-displayRotation, frame.exactCenterX(), frame.exactCenterY());
    matrix.postScale(cameraFlip ? -1 : 1, 1, frame.exactCenterX(), frame.exactCenterY());
    matrix.postRotate(cameraRotation, frame.exactCenterX(), frame.exactCenterY());

    invalidate();
}