Example usage for android.graphics Matrix Matrix

List of usage examples for android.graphics Matrix Matrix

Introduction

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

Prototype

public Matrix() 

Source Link

Document

Create an identity matrix

Usage

From source file:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java

private String compressAndSaveImage(String fileImage, int scale) throws Exception {
    try {//from  w  w w .  ja  v  a2  s. c  om
        ExifInterface exif = new ExifInterface(fileImage);
        String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
        String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int rotate = 0;
        if (BuildConfig.DEBUG) {
            Log.i(TAG, "Before: " + width + "x" + length);
        }

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = -90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = 90;
            break;
        }

        int w = Integer.parseInt(width);
        int l = Integer.parseInt(length);

        int what = w > l ? w : l;

        Options options = new Options();
        if (what > 1500) {
            options.inSampleSize = scale * 4;
        } else if (what > 1000 && what <= 1500) {
            options.inSampleSize = scale * 3;
        } else if (what > 400 && what <= 1000) {
            options.inSampleSize = scale * 2;
        } else {
            options.inSampleSize = scale;
        }
        if (BuildConfig.DEBUG) {
            Log.i(TAG, "Scale: " + (what / options.inSampleSize));
            Log.i(TAG, "Rotate: " + rotate);
        }
        Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options);
        File original = new File(fileImage);
        File file = new File((original.getParent() + File.separator
                + original.getName().replace(".", "_fact_" + scale + ".")));
        FileOutputStream stream = new FileOutputStream(file);
        if (rotate != 0) {
            Matrix matrix = new Matrix();
            matrix.setRotate(rotate);
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
        }
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

        if (BuildConfig.DEBUG) {
            ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath());
            String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
            String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
            if (BuildConfig.DEBUG) {
                Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter);
            }
        }
        stream.flush();
        stream.close();
        return file.getAbsolutePath();

    } catch (IOException e) {
        e.printStackTrace();
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Corrupt or deleted file???");
    }
}

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);
    }// w  w  w  .  j  av a 2  s. c  om

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

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

private void init() {
    setWillNotDraw(false);//from  w  w  w.j  a v a2  s .  co m
    setClickable(true);

    mChildTransfromer = new Matrix();
    mReflectionTransfromer = new Matrix();

    mTouchRect = new RectF();

    mImageRecorder = new SparseArray<int[]>();

    mDrawChildPaint = new Paint();
    mDrawChildPaint.setAntiAlias(true);
    mDrawChildPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    mCoverFlowPadding = new Rect();

    mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

    mScroller = new Scroller(getContext(), new AccelerateDecelerateInterpolator());

    mRemoveReflectionPendingArray = new ArrayList<Integer>();
}

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:com.netcompss.ffmpeg4android_client.BaseVideo.java

@SuppressWarnings("unused")
private String reporteds(String path) {

    ExifInterface exif = null;/* w w  w. jav a 2s. com*/
    try {
        exif = new ExifInterface(path);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    Matrix matrix = new Matrix();
    if (orientation == 6) {
        matrix.postRotate(90);
    } else if (orientation == 3) {
        matrix.postRotate(180);
    } else if (orientation == 8) {
        matrix.postRotate(270);
    }

    if (path != null) {

        if (path.contains("http")) {
            try {
                URL url = new URL(path);
                HttpGet httpRequest = null;

                httpRequest = new HttpGet(url.toURI());

                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

                HttpEntity entity = response.getEntity();
                BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
                InputStream input = bufHttpEntity.getContent();

                Bitmap bitmap = BitmapFactory.decodeStream(input);
                input.close();
                return getPath(bitmap);
            } catch (MalformedURLException e) {
                Log.e("ImageActivity", "bad url", e);
            } catch (Exception e) {
                Log.e("ImageActivity", "io error", e);
            }
        } else {

            Options options = new Options();
            options.inSampleSize = 2;
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeResource(context.getResources(), srcBgId, options);
            options.inJustDecodeBounds = false;
            options.inSampleSize = calculateInSampleSize(options, w, h);
            Bitmap unbgbtmp = BitmapFactory.decodeResource(context.getResources(), srcBgId, options);
            Bitmap unrlbtmp = ScalingUtilities.decodeFile(path, w, h, ScalingLogic.FIT);
            unrlbtmp.recycle();
            Bitmap rlbtmp = null;
            if (unrlbtmp != null) {
                rlbtmp = ScalingUtilities.createScaledBitmap(unrlbtmp, w, h, ScalingLogic.FIT);
            }
            if (unbgbtmp != null && rlbtmp != null) {
                Bitmap bgbtmp = ScalingUtilities.createScaledBitmap(unbgbtmp, w, h, ScalingLogic.FIT);
                Bitmap newscaledBitmap = ProcessingBitmapTwo(bgbtmp, rlbtmp);
                unbgbtmp.recycle();
                return getPath(newscaledBitmap);
            }
        }
    }
    return path;

}

From source file:com.scm.reader.livescanner.sdk.recognizers.KooabaRecognizer.java

private Bitmap fixRotation(Bitmap img) throws IOException {
    //get WINDOW_SERVICE
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    if (isDebugLog()) {
        logDebug("Display orientation is " + display.getOrientation());
    }//  ww w. j ava  2s  .  c om

    Matrix m = new Matrix();

    int angle = 0;

    //TODO: refactor
    if (img.getWidth() > img.getHeight()) {
        if (display.getOrientation() == ROTATION_0) {
            angle = 90;
        } else if (display.getOrientation() == ROTATION_270) {
            angle = 180;
        }
    } else {
        if (display.getOrientation() == ROTATION_90) {
            angle = -90;
        } else if (display.getOrientation() == ROTATION_270) {
            angle = 90;
        }
    }

    if (isDebugLog()) {
        logDebug("Preview image will be rotated by " + angle + " degrees");
    }

    m.postRotate(angle);
    return Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), m, true);
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

public void save(int width, int height, boolean transparentBackground, File sigFile) throws IOException {
    if (mNotInitialized)
        return;/*from  ww  w.  java  2 s.  com*/

    float scale = Math.min((float) width / getWidth(), (float) height / getHeight());
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);

    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    canvas.setMatrix(matrix);

    int color = transparentBackground ? Color.TRANSPARENT : 0xFFFFFF - mPaint.getColor();
    drawSign(canvas, color, mPaint);
    if (sigFile.exists() || sigFile.createNewFile()) {
        FileOutputStream out = new FileOutputStream(sigFile);
        bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
    }
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

private void init() {
    setWillNotDraw(false);//from w  w w  .  ja va2 s .co  m
    setClickable(true);

    mChildTransformer = new Matrix();
    mReflectionTransformer = new Matrix();

    mTouchRect = new RectF();

    mImageRecorder = new SparseArray<int[]>();

    mDrawChildPaint = new Paint();
    mDrawChildPaint.setAntiAlias(true);
    mDrawChildPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    mCoverFlowPadding = new Rect();

    mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

    mScroller = new Scroller(getContext(), new AccelerateDecelerateInterpolator());
}

From source file:com.phonegap.customcamera.NativeCameraLauncher.java

private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap, ExifHelper exif) {
    Matrix matrix = new Matrix();
    matrix.setRotate(rotate);//from w ww  .j  a  va2  s .c o m
    try {
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        exif.resetOrientation();
    } catch (OutOfMemoryError oom) {
        // You can run out of memory if the image is very large:
        // http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html
        // If this happens, simply do not rotate the image and return it unmodified.
        // If you do not catch the OutOfMemoryError, the Android app crashes.
    }
    return bitmap;
}

From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java

/**
 * Decode rss item image thad storing in given file
 * @param imagePath - image file path/* www  . j ava2  s  .  c o  m*/
 * @return decoded image Bitmap
 */
private Bitmap decodeImageFile(String imagePath) {
    try {
        File file = new File(imagePath);
        //Decode image size
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(file), null, opts);

        //Find the correct scale value. It should be the power of 2.
        int width = opts.outWidth, height = opts.outHeight;
        int scale = 1;
        while (true) {
            if (width / 2 < imageWidth || height / 2 < imageHeight) {
                break;
            }
            width /= 2;
            height /= 2;
            scale *= 2;
        }

        //Decode with inSampleSize
        opts = new BitmapFactory.Options();
        opts.inSampleSize = scale;

        Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(file), null, opts);

        int x = 0, y = 0, l = 0;
        if (width > height) {
            x = (int) (width - height) / 2;
            y = 0;
            l = height;
        } else {
            x = 0;
            y = (int) (height - width) / 2;
            l = width;
        }

        float matrixScale = (float) (imageWidth - 4) / (float) l;
        Matrix matrix = new Matrix();
        matrix.postScale(matrixScale, matrixScale);

        return Bitmap.createBitmap(bitmap, x, y, l, l, matrix, true);
    } catch (Exception e) {
    }

    return null;
}