Example usage for android.media ExifInterface getAttributeInt

List of usage examples for android.media ExifInterface getAttributeInt

Introduction

In this page you can find the example usage for android.media ExifInterface getAttributeInt.

Prototype

public int getAttributeInt(String tag, int defaultValue) 

Source Link

Document

Returns the integer value of the specified tag.

Usage

From source file:mobisocial.bento.todo.ui.TodoListFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (DEBUG)/*from  ww  w .  j  av  a2 s. com*/
        Log.d(TAG, "requestCode: " + requestCode + ", resultCode: " + resultCode);
    if (resultCode == Activity.RESULT_OK) {
        try {
            File imageFile = null;

            if (requestCode == REQUEST_IMAGE_CAPTURE) {

                imageFile = JpgFileHelper.getTmpFile();

            } else if (requestCode == REQUEST_GALLERY) {
                Uri uri = data.getData();
                if (uri == null || uri.toString().length() == 0) {
                    return;
                }

                if (DEBUG)
                    Log.d(TAG, "data URI: " + uri.toString());

                ContentResolver cr = getActivity().getContentResolver();
                String[] columns = { MediaColumns.DATA, MediaColumns.DISPLAY_NAME };
                Cursor c = cr.query(uri, columns, null, null, null);

                if (c != null && c.moveToFirst()) {
                    if (c.getString(0) != null) {
                        //regular processing for gallery files
                        imageFile = new File(c.getString(0));
                    } else {
                        final InputStream is = getActivity().getContentResolver().openInputStream(uri);
                        imageFile = JpgFileHelper.saveTmpFile(is);
                        is.close();
                    }
                } else if (uri.toString().startsWith("content://com.android.gallery3d.provider")) {
                    // motorola xoom doesn't work for contentresolver even if the image comes from picasa.
                    // So just adds the condition of startsWith...
                    // See in detail : http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/
                    uri = Uri.parse(
                            uri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d"));
                    final InputStream is = getActivity().getContentResolver().openInputStream(uri);
                    imageFile = JpgFileHelper.saveTmpFile(is);
                    is.close();
                } else {
                    // http or https
                    HttpURLConnection http = null;
                    URL url = new URL(uri.toString());
                    http = (HttpURLConnection) url.openConnection();
                    http.setRequestMethod("GET");
                    http.connect();

                    final InputStream is = http.getInputStream();
                    imageFile = JpgFileHelper.saveTmpFile(is);
                    is.close();
                    if (http != null)
                        http.disconnect();
                }
            }

            if (imageFile.exists() && imageFile.length() > 0) {
                if (DEBUG)
                    Log.d(TAG, "imageFile exists=" + imageFile.exists() + " length=" + imageFile.length()
                            + " path=" + imageFile.getPath());

                float degrees = 0;
                try {
                    ExifInterface exif = new ExifInterface(imageFile.getPath());
                    switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                            ExifInterface.ORIENTATION_NORMAL)) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        degrees = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        degrees = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        degrees = 270;
                        break;
                    default:
                        degrees = 0;
                        break;
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Bitmap bitmap = BitmapHelper.getResizedBitmap(imageFile, BitmapHelper.MAX_IMAGE_WIDTH,
                        BitmapHelper.MAX_IMAGE_HEIGHT, degrees);

                TodoListItem item = new TodoListItem();
                item.uuid = UUID.randomUUID().toString();
                item.title = "";
                item.description = "";
                item.bDone = false;
                item.hasImage = true;
                item.creDateMillis = System.currentTimeMillis();
                item.modDateMillis = System.currentTimeMillis();
                item.creContactId = mManager.getLocalContactId();
                item.modContactId = mManager.getLocalContactId();

                StringBuilder msg = new StringBuilder(
                        getString(R.string.feed_msg_added_photo, mManager.getLocalName()));
                String plainMsg = UIUtils.getPlainString(mManager.getBentoListItem().bento.name,
                        msg.toString());

                mManager.addTodo(item, bitmap, plainMsg);

                refreshView();

                JpgFileHelper.deleteTmpFile();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java

private Bitmap getPortraitImage(String imagePath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;/*w w  w  .  j a  va 2  s. co  m*/
    Bitmap photo = BitmapFactory.decodeFile(output.getPath(), options);
    float rotateAngle;
    try {
        ExifInterface exifInterface = new ExifInterface(imagePath);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotateAngle = 270;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotateAngle = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotateAngle = 90;
            break;
        default:
            rotateAngle = 0;
            break;
        }
        return rotateImage(photo, rotateAngle);
    } catch (IOException e) {
        logger.e(e.getMessage());
        return photo;
    }
}

From source file:com.cars.manager.utils.imageChooser.threads.MediaProcessorThread.java

private String compressAndSaveImage(String fileImage, int scale) throws Exception {
    try {//from w  ww.  j ava2s  .  co  m
        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 (Config.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 (Config.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 (Config.DEBUG) {
            ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath());
            String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
            String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
            if (Config.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:com.haru.ui.image.workers.MediaProcessorThread.java

private String compressAndSaveImage(String fileImage, int scale) throws Exception {
    try {//from   ww  w. j av a 2  s  . c o  m
        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 (/* TODO: DEBUG */ true) {
            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 (/* TODO: DEBUG */ true) {
            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 (/* TODO: DEBUG */ true) {
            ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath());
            String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
            String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
            if (/* TODO: DEBUG */ true) {
                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:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java

private String compressAndSaveImage(String fileImage, int scale) throws Exception {
    try {//from   w  ww  .  j a  va  2  s.  c o m
        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:com.yk.notification.util.BitmapUtil.java

/**
 * ?//from   w w w  .j av  a 2  s . c om
 * 
 * @param path
 *            ?
 * @return 
 */
public static int getImageDegree(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            degree = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            degree = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            degree = 270;
            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}

From source file:com.wots.lutmaar.CustomView.imagechooser.threads.MediaProcessorThread.java

private String compressAndSaveImage(String fileImage, int scale) throws Exception {
    try {/*from  ww w . j a  v  a 2s. co m*/
        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);

        }
        /* if (scale == 1)
        bitmap = Bitmap.createScaledBitmap(bitmap, 240, 260, true);*/
        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:mobisocial.bento.ebento.ui.EditFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (DEBUG)//from w ww. ja v a 2  s.  c o m
        Log.d(TAG, "requestCode: " + requestCode + ", resultCode: " + resultCode);
    if (resultCode == Activity.RESULT_OK) {
        try {
            File imageFile = null;

            if (requestCode == REQUEST_IMAGE_CAPTURE) {

                imageFile = JpgFileHelper.getTmpFile();

            } else if (requestCode == REQUEST_GALLERY) {
                Uri uri = data.getData();
                if (uri == null || uri.toString().length() == 0) {
                    return;
                }
                if (DEBUG)
                    Log.d(TAG, "data URI: " + uri.toString());

                ContentResolver cr = getActivity().getContentResolver();
                String[] columns = { MediaColumns.DATA, MediaColumns.DISPLAY_NAME };
                Cursor c = cr.query(uri, columns, null, null, null);

                if (c != null && c.moveToFirst()) {
                    if (c.getString(0) != null) {
                        //regular processing for gallery files
                        imageFile = new File(c.getString(0));
                    } else {
                        final InputStream is = getActivity().getContentResolver().openInputStream(uri);
                        imageFile = JpgFileHelper.saveTmpFile(is);
                        is.close();
                    }
                } else if (uri.toString().startsWith("content://com.android.gallery3d.provider")) {
                    // motorola xoom doesn't work for contentresolver even if the image comes from picasa.
                    // So just adds the condition of startsWith...
                    // See in detail : http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/
                    uri = Uri.parse(
                            uri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d"));
                    final InputStream is = getActivity().getContentResolver().openInputStream(uri);
                    imageFile = JpgFileHelper.saveTmpFile(is);
                    is.close();
                } else {
                    // http or https
                    HttpURLConnection http = null;
                    URL url = new URL(uri.toString());
                    http = (HttpURLConnection) url.openConnection();
                    http.setRequestMethod("GET");
                    http.connect();

                    final InputStream is = http.getInputStream();
                    imageFile = JpgFileHelper.saveTmpFile(is);
                    is.close();
                    if (http != null)
                        http.disconnect();
                }
            }

            if (imageFile.exists() && imageFile.length() > 0) {
                if (DEBUG)
                    Log.d(TAG, "imageFile exists=" + imageFile.exists() + " length=" + imageFile.length()
                            + " path=" + imageFile.getPath());

                float degrees = 0;
                try {
                    ExifInterface exif = new ExifInterface(imageFile.getPath());
                    switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                            ExifInterface.ORIENTATION_NORMAL)) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        degrees = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        degrees = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        degrees = 270;
                        break;
                    default:
                        degrees = 0;
                        break;
                    }
                    Log.d(TAG, exif.getAttribute(ExifInterface.TAG_ORIENTATION));
                } catch (IOException e) {
                    e.printStackTrace();
                }

                sImageOrg = BitmapHelper.getResizedBitmap(imageFile, BitmapHelper.MAX_IMAGE_WIDTH,
                        BitmapHelper.MAX_IMAGE_HEIGHT, degrees);
                mbImageChanged = true;

                // ImageView
                mImageView.setImageBitmap(
                        BitmapHelper.getResizedBitmap(sImageOrg, mTargetWidth, mTargetHeight, 0));
                mImageView.setVisibility(View.VISIBLE);
                mRootView.invalidate();

                imageFile.delete();
                JpgFileHelper.deleteTmpFile();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.cloverstudio.spika.CameraCropActivity.java

protected void onPhotoTaken(String path) {

    String fileName = Uri.parse(path).getLastPathSegment();
    mFilePath = CameraCropActivity.this.getExternalCacheDir() + "/" + fileName;

    if (!path.equals(mFilePath)) {
        copy(new File(path), new File(mFilePath));
    }//from   www.  j  a v  a 2  s.  c o m

    new AsyncTask<String, Void, byte[]>() {
        boolean loadingFailed = false;

        @Override
        protected byte[] doInBackground(String... params) {
            try {

                if (params == null)
                    return null;

                File f = new File(params[0]);
                ExifInterface exif = new ExifInterface(f.getPath());
                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_NORMAL);

                int angle = 0;

                if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
                    angle = 90;
                } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
                    angle = 180;
                } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
                    angle = 270;
                }

                Matrix mat = new Matrix();
                mat.postRotate(angle);

                BitmapFactory.Options optionsMeta = new BitmapFactory.Options();
                optionsMeta.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(f.getAbsolutePath(), optionsMeta);

                BitmapFactory.Options options = new BitmapFactory.Options();

                options.inSampleSize = BitmapManagement.calculateInSampleSize(optionsMeta, 640, 640);
                options.inPurgeable = true;
                options.inInputShareable = true;
                mBitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, options);
                mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), mat,
                        true);
                _scaleBitmap();
                return null;
            } catch (Exception ex) {
                loadingFailed = true;
                finish();
            }

            return null;
        }

        @Override
        protected void onPostExecute(byte[] result) {
            super.onPostExecute(result);

            if (null != mBitmap) {
                mImageView.setImageBitmap(mBitmap);
                mImageView.setScaleType(ScaleType.MATRIX);
                translateMatrix.setTranslate(-(mBitmap.getWidth() - crop_container_size) / 2f,
                        -(mBitmap.getHeight() - crop_container_size) / 2f);
                mImageView.setImageMatrix(translateMatrix);

                matrix = translateMatrix;

            }

        }
    }.execute(mFilePath);

}

From source file:me.tipi.kiosk.ui.fragments.OCRFragment.java

@Override
public void onMetadataAvailable(Metadata metadata) {
    // This method will be called when metadata becomes available during recognition process.
    // Here, for every metadata type that is allowed through metadata settings,
    // desired actions can be performed.
    // detection metadata contains detection locations
    if (metadata instanceof DetectionMetadata) {
        // detection location is written inside DetectorResult
        DetectorResult detectorResult = ((DetectionMetadata) metadata).getDetectionResult();
        // DetectorResult can be null - this means that detection has failed
        if (detectorResult == null) {
            if (mQvManager != null) {
                // begin quadrilateral animation to its default position
                // (internally displays FAIL status)
                mQvManager.animateQuadToDefaultPosition();
            }/*from   w w w . ja  v  a 2s  . co  m*/
            // when points of interested have been detected (e.g. QR code), this will be returned as PointsDetectorResult
        } else if (detectorResult instanceof QuadDetectorResult) {
            // begin quadrilateral animation to detected quadrilateral
            mQvManager.animateQuadToDetectionPosition((QuadDetectorResult) detectorResult);
        }
    } else if (metadata instanceof ImageMetadata) {
        // obtain image
        // Please note that Image's internal buffers are valid only
        // until this method ends. If you want to save image for later,
        // obtained a cloned image with image.clone().

        if (guest.passportPath == null || TextUtils.isEmpty(guest.passportPath) || this.results == null) {
            Image image = ((ImageMetadata) metadata).getImage();

            if (image != null && image.getImageType() == ImageType.SUCCESSFUL_SCAN) {
                Timber.w("Metadata type is successful frame image, we go to save it");
                image.clone();
                Timber.w("Ocr meta data captured");
                final Bitmap bitmap = image.convertToBitmap();
                Timber.w("Metadata converted to bitmap");
                final Uri photoUri = ImageUtility.savePassportPicture(getActivity(), bitmap);
                Timber.w("OCR Uri got back from file helper with path: %s",
                        photoUri != null ? photoUri.getPath() : "NO OCR FILE PATH!!!!!");
                ExifInterface ei = null;
                try {
                    ei = new ExifInterface(photoUri.getPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }

                int orientation = ei != null
                        ? ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
                        : 0;
                Timber.w("Ocr image orientation angle is: %d", orientation);

                Bitmap rotated = null;

                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotated = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotated = rotateImage(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotated = rotateImage(bitmap, 270);
                    break;
                case ExifInterface.ORIENTATION_UNDEFINED:
                    rotated = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_NORMAL:
                default:
                    break;
                }

                final Uri rotatedUri = ImageUtility.savePassportPicture(getActivity(), rotated);
                Timber.w("OCR ROTATED Uri got back from file helper with path: %s",
                        rotatedUri != null ? rotatedUri.getPath() : "NO OCR FILE PATH!!!!!");
                guest.passportPath = rotatedUri.getPath();
                Timber.w("Ocr path saved with path: %s", rotatedUri.getPath());
            }
        } else {
            Timber.w("We have ocr path and it's : %s", guest.passportPath);
        }
        // to convert the image to Bitmap, call image.convertToBitmap()

        // after this line, image gets disposed. If you want to save it
        // for later, you need to clone it with image.clone()
    }
}