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) 

Source Link

Document

Postconcats the matrix with the specified scale.

Usage

From source file:com.example.android.camera.CameraActivity.java

public static void prepareMatrix(Matrix matrix, int displayOrientation, int viewWidth, int viewHeight) {

    Log.d("face CameraPreview", "Width: " + viewWidth + " Height: " + viewHeight);

    // This is the value for android.hardware.Camera.setDisplayOrientation.
    matrix.postRotate(displayOrientation);

    // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
    // UI coordinates range from (0, 0) to (width, height).
    // Log.d("face View", "Width: " + viewWidth + " x Height: " + viewHeight);
    matrix.postScale(viewWidth / 2000f, viewHeight / 2000f);
    //        matrix.postTranslate(viewWidth / 2f, viewHeight / 2f);
    matrix.setTranslate(viewWidth / 2f, viewHeight / 2f);
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap scaleImage(Bitmap bitmap, int boundBoxInDp) {
    // Get current dimensions
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    // Determine how much to scale: the dimension requiring less scaling is
    // closer to the its side. This way the image always stays inside your
    // bounding box AND either x/y axis touches it.
    float xScale = ((float) boundBoxInDp) / width;
    float yScale = ((float) boundBoxInDp) / height;
    float scale = (xScale <= yScale) ? xScale : yScale;

    // Create a matrix for the scaling and add the scaling data
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    // Create a new bitmap and convert it to a format understood by the ImageView
    Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return scaledBitmap;
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap scaleImageInPixels(Bitmap bitmap, int pixels) {
    // Get current dimensions
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    // Determine how much to scale: the dimension requiring less scaling is
    // closer to the its side. This way the image always stays inside your
    // bounding box AND either x/y axis touches it.
    float xScale = ((float) pixels) / width;
    float yScale = ((float) pixels) / height;
    float scale = (xScale <= yScale) ? xScale : yScale;

    // Create a matrix for the scaling and add the scaling data
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    // Create a new bitmap and convert it to a format understood by the ImageView
    Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return scaledBitmap;
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private static Matrix getRotateMatrix(int ori) {
    Matrix matrix = new Matrix();
    switch (ori) {
    case 2:/*from   w  w w .j a va2  s.  c om*/
        matrix.setScale(-1, 1);
        break;
    case 3:
        matrix.setRotate(180);
        break;
    case 4:
        matrix.setRotate(180);
        matrix.postScale(-1, 1);
        break;
    case 5:
        matrix.setRotate(90);
        matrix.postScale(-1, 1);
        break;
    case 6:
        matrix.setRotate(90);
        break;
    case 7:
        matrix.setRotate(-90);
        matrix.postScale(-1, 1);
        break;
    case 8:
        matrix.setRotate(-90);
        break;
    }
    return matrix;
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.IconCache.java

private Bitmap resize(Bitmap bitmap) {
    int size = Math.max(bitmap.getHeight(), bitmap.getWidth());
    if (size <= mIconSize) {
        return bitmap;
    }/*from w  w w  .  j av  a 2  s.c  o m*/
    float downScale = ((float) mIconSize) / size;
    Matrix matrix = new Matrix();
    matrix.postScale(downScale, downScale);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:at.wada811.imageviewscaling.ImageViewFragment.java

public ParameterDelegate getParameterDelegate() {
    return new ParameterDelegate() {
        @Override/*from  w  w w  .  j  a  v  a 2  s  . c om*/
        public ScaleType getScaleType() {
            return mImageView.getScaleType();
        }

        @Override
        public void setScaleType(ScaleType scaleType) {
            mImageView.setScaleType(scaleType);
        }

        @Override
        public int getLayoutParamsWidth() {
            return mImageView.getLayoutParams().width;
        }

        @Override
        public void setLayoutParamsWidth(int width) {
            LayoutParams params = mImageView.getLayoutParams();
            params.width = width;
            mImageView.setLayoutParams(params);
        }

        @Override
        public int getLayoutParamsHeight() {
            return mImageView.getLayoutParams().height;
        }

        @Override
        public void setLayoutParamsHeight(int height) {
            LayoutParams params = mImageView.getLayoutParams();
            params.height = height;
            mImageView.setLayoutParams(params);

        }

        @Override
        public boolean getAdjustViewBounds() {
            return mImageView.getAdjustViewBounds();
        }

        @Override
        public void setAdjustViewBounds(boolean adjustViewBounds) {
            mImageView.setAdjustViewBounds(adjustViewBounds);
        }

        @Override
        public void setFitDisplayInside() {
            Bitmap bitmap = BitmapUtils.createBitmapFromDrawable(mImageView.getDrawable());
            float factor = (float) DisplayUtils.getWidth(getActivity()) / bitmap.getWidth();
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    DisplayUtils.getWidth(getActivity()), (int) (bitmap.getHeight() * factor));
            mImageView.setLayoutParams(params);
            Matrix matrix = mImageView.getImageMatrix();
            matrix.reset();
            matrix.postScale(factor, factor);
            mImageView.setImageMatrix(matrix);

        }
    };
}

From source file:com.webXells.ImageResizer.ImageResizePlugin.java

public Bitmap getResizedBitmap(Bitmap bm, float widthFactor, float heightFactor) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(widthFactor, heightFactor);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

From source file:Main.java

/**
 * Returns a transformation matrix from one reference frame into another.
 * Handles cropping (if maintaining aspect ratio is desired) and rotation.
 *
 * @param srcWidth Width of source frame.
 * @param srcHeight Height of source frame.
 * @param dstWidth Width of destination frame.
 * @param dstHeight Height of destination frame.
 * @param applyRotation Amount of rotation to apply from one frame to another.
 *  Must be a multiple of 90./*from w  w w  . j  a  va  2s. c om*/
 * @param maintainAspectRatio If true, will ensure that scaling in x and y remains constant,
 * cropping the image if necessary.
 * @return The transformation fulfilling the desired requirements.
 */
public static Matrix getTransformationMatrix(final int srcWidth, final int srcHeight, final int dstWidth,
        final int dstHeight, final int applyRotation, final boolean maintainAspectRatio) {
    final Matrix matrix = new Matrix();

    if (applyRotation != 0) {
        // Translate so center of image is at origin.
        matrix.postTranslate(-srcWidth / 2.0f, -srcHeight / 2.0f);

        // Rotate around origin.
        matrix.postRotate(applyRotation);
    }

    // Account for the already applied rotation, if any, and then determine how
    // much scaling is needed for each axis.
    final boolean transpose = (Math.abs(applyRotation) + 90) % 180 == 0;

    final int inWidth = transpose ? srcHeight : srcWidth;
    final int inHeight = transpose ? srcWidth : srcHeight;

    // Apply scaling if necessary.
    if (inWidth != dstWidth || inHeight != dstHeight) {
        final float scaleFactorX = dstWidth / (float) inWidth;
        final float scaleFactorY = dstHeight / (float) inHeight;

        if (maintainAspectRatio) {
            // Scale by minimum factor so that dst is filled completely while
            // maintaining the aspect ratio. Some image may fall off the edge.
            final float scaleFactor = Math.max(scaleFactorX, scaleFactorY);
            matrix.postScale(scaleFactor, scaleFactor);
        } else {
            // Scale exactly to fill dst from src.
            matrix.postScale(scaleFactorX, scaleFactorY);
        }
    }

    if (applyRotation != 0) {
        // Translate back from origin centered reference to destination frame.
        matrix.postTranslate(dstWidth / 2.0f, dstHeight / 2.0f);
    }

    return matrix;
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private static Matrix getRotateMatrix(int ori) {

    Matrix matrix = new Matrix();
    switch (ori) {
    case 2:/*w w  w  .j  a  v a  2  s  .c o  m*/
        matrix.setScale(-1, 1);
        break;
    case 3:
        matrix.setRotate(180);
        break;
    case 4:
        matrix.setRotate(180);
        matrix.postScale(-1, 1);
        break;
    case 5:
        matrix.setRotate(90);
        matrix.postScale(-1, 1);
        break;
    case 6:
        matrix.setRotate(90);
        break;
    case 7:
        matrix.setRotate(-90);
        matrix.postScale(-1, 1);
        break;
    case 8:
        matrix.setRotate(-90);
        break;

    }

    return matrix;

}

From source file:com.leo.runningman.ui.ImageDetailActivity.java

private Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}