Example usage for android.graphics Matrix postScale

List of usage examples for android.graphics Matrix postScale

Introduction

In this page you can find the example usage for android.graphics Matrix postScale.

Prototype

public boolean postScale(float sx, float sy, float px, float py) 

Source Link

Document

Postconcats the matrix with the specified scale.

Usage

From source file:Main.java

public static Bitmap scaleBitmapSoft(Bitmap temp, float scaleSize) {
    if (!canUse(temp)) {
        return null;
    }//from ww w . j  a  va2  s. c o m
    Matrix m = new Matrix();
    m.postScale(scaleSize, scaleSize, 0, 0);
    return Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), m, true);
}

From source file:ca.frozen.rpicameraviewer.views.ZoomPanTextureView.java

private void setTransform() {
    // get the view size
    int viewWidth = getWidth();
    int viewHeight = getHeight();

    // scale relative to the center
    Matrix transform = new Matrix();
    transform.postScale(fitZoom.x * zoom, fitZoom.y * zoom, viewWidth / 2, viewHeight / 2);

    // add the panning
    if (pan.x != 0 || pan.y != 0) {
        transform.postTranslate(pan.x, pan.y);
    }//from   www.j a v  a2  s . co  m

    // set the transform
    setTransform(transform);
    invalidate();
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

protected void zoomOut(float rate) {
    if (mBitmap == null) {
        return;//w  ww.j a va  2  s  . c  om
    }

    float width = getWidth();
    float height = getHeight();

    Matrix tmp = new Matrix(mSuppMatrix);
    tmp.postScale(1F / sScaleRate, 1F / sScaleRate, width / 2F, height / 2F);
    if (getScale(tmp) < 1F) {
        mSuppMatrix.setScale(1F, 1F, width / 2F, height / 2F);
    } else {
        mSuppMatrix.postScale(1F / rate, 1F / rate, width / 2F, height / 2F);
    }
    setImageMatrix(getImageViewMatrix());
    center(true, true, false);

}

From source file:com.goka.flickableview.ImageViewTouchBase.java

protected void zoomTo(float scale, float centerX, float centerY, final long durationMs) {
    if (scale > getMaxScale()) {
        scale = getMaxScale();//from  w  w w. j  a  v a  2  s .c om
    }

    final float oldScale = getScale();

    Matrix m = new Matrix(mSuppMatrix);
    m.postScale(scale, scale, centerX, centerY);
    RectF rect = getCenter(m, true, true);

    final float finalScale = scale;
    final float destX = centerX + rect.left * scale;
    final float destY = centerY + rect.top * scale;

    stopAllAnimations();

    ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator();
    animatorCompat.setDuration(durationMs);
    final Interpolator interpolator = new DecelerateInterpolator(1.0f);
    animatorCompat.addUpdateListener(new AnimatorUpdateListenerCompat() {
        @Override
        public void onAnimationUpdate(ValueAnimatorCompat animation) {
            float fraction = interpolator.getInterpolation(animation.getAnimatedFraction());
            float value = oldScale + (fraction * (finalScale - oldScale));
            zoomTo(value, destX, destY);
        }
    });
    animatorCompat.start();
}

From source file:com.digitalvotingpass.camera.CameraFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//*from www. ja va 2s.  c o m*/
public void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
    overlay.setRect(CameraFragmentUtil.getScanRect(scanSegment));
}

From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///from   ww w. j a v a 2s  .  c  o  m
private void configureTransform(int viewWidth, int viewHeight) {
    if (isViewAvailable()) {
        if (null == activityView.getTextureView()) {
            return;
        }
        int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation();
        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 == rotation || Surface.ROTATION_270 == rotation) {
            bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
            matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
            float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                    (float) viewWidth / previewSize.getWidth());
            matrix.postScale(scale, scale, centerX, centerY);
            matrix.postRotate(90 * (rotation - 2), centerX, centerY);
        } else if (Surface.ROTATION_180 == rotation) {
            matrix.postRotate(180, centerX, centerY);
        }
        activityView.getTextureView().setTransform(matrix);
    }
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

/**
 * This function calculates a Image to Screen Transformation matrix
 *
 * @param reflectRotation set true if you want the rotation encoded
 * @return Image to Screen transformation matrix
 *//*from  w w  w  .ja v  a  2  s . co  m*/
protected Matrix getImageToScreenMatrix(boolean reflectRotation) {
    MasterImage master = MasterImage.getImage();
    if (master.getOriginalBounds() == null) {
        return new Matrix();
    }
    Matrix m = GeometryMathUtils.getImageToScreenMatrix(master.getPreset().getGeometryFilters(),
            reflectRotation, master.getOriginalBounds(), getWidth(), getHeight());
    Point translate = master.getTranslation();
    float scaleFactor = master.getScaleFactor();
    m.postTranslate(translate.x, translate.y);
    m.postScale(scaleFactor, scaleFactor, getWidth() / 2.0f, getHeight() / 2.0f);
    return m;
}

From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `textureView`. This
 * method should be called after the camera preview size is determined in setUpCameraOutputs and
 * also the size of `textureView` is fixed.
 *
 * @param viewWidth The width of `textureView`
 * @param viewHeight The height of `textureView`
 *//*  www .  j a  v  a2  s.c o  m*/
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    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 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}

From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//*w ww. j a va2 s .  c  o m*/
@DebugLog
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}

From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `textureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until the size of `textureView` is fixed.
 *
 * @param viewWidth  The width of `textureView`
 * @param viewHeight The height of `textureView`
 *///from  w  ww .ja  v  a  2s .c o m
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    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 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    }
    textureView.setTransform(matrix);
}