Example usage for android.media ExifInterface ORIENTATION_UNDEFINED

List of usage examples for android.media ExifInterface ORIENTATION_UNDEFINED

Introduction

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

Prototype

int ORIENTATION_UNDEFINED

To view the source code for android.media ExifInterface ORIENTATION_UNDEFINED.

Click Source Link

Usage

From source file:com.klinker.android.twitter.activities.compose.Compose.java

private Bitmap getThumbnail(Uri uri) throws FileNotFoundException, IOException {
    InputStream input = getContentResolver().openInputStream(uri);
    int reqWidth = 150;
    int reqHeight = 150;

    byte[] byteArr = new byte[0];
    byte[] buffer = new byte[1024];
    int len;/*from   w  w w.  jav a2 s.c om*/
    int count = 0;

    try {
        while ((len = input.read(buffer)) > -1) {
            if (len != 0) {
                if (count + len > byteArr.length) {
                    byte[] newbuf = new byte[(count + len) * 2];
                    System.arraycopy(byteArr, 0, newbuf, 0, count);
                    byteArr = newbuf;
                }

                System.arraycopy(buffer, 0, byteArr, count, len);
                count += len;
            }
        }

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);

        b = ImageUtils.cropSquare(b);

        return rotateBitmap(b, orientation);

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

        return null;
    }
}

From source file:com.daiv.android.twitter.ui.compose.Compose.java

private Bitmap getThumbnail(Uri uri) throws IOException {
    InputStream input = getContentResolver().openInputStream(uri);
    int reqWidth = 150;
    int reqHeight = 150;

    byte[] byteArr = new byte[0];
    byte[] buffer = new byte[1024];
    int len;/* w  w w .  j  a  v  a  2 s.c  om*/
    int count = 0;

    try {
        while ((len = input.read(buffer)) > -1) {
            if (len != 0) {
                if (count + len > byteArr.length) {
                    byte[] newbuf = new byte[(count + len) * 2];
                    System.arraycopy(byteArr, 0, newbuf, 0, count);
                    byteArr = newbuf;
                }

                System.arraycopy(buffer, 0, byteArr, count, len);
                count += len;
            }
        }

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);

        b = ImageUtils.cropSquare(b);

        return rotateBitmap(b, orientation);

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

        return null;
    }
}

From source file:com.daiv.android.twitter.ui.compose.Compose.java

public Bitmap getBitmapToSend(Uri uri) throws IOException {
    InputStream input = getContentResolver().openInputStream(uri);
    int reqWidth = 750;
    int reqHeight = 750;

    byte[] byteArr = new byte[0];
    byte[] buffer = new byte[1024];
    int len;//from   ww  w  .  ja v  a2 s  . c om
    int count = 0;

    try {
        while ((len = input.read(buffer)) > -1) {
            if (len != 0) {
                if (count + len > byteArr.length) {
                    byte[] newbuf = new byte[(count + len) * 2];
                    System.arraycopy(byteArr, 0, newbuf, 0, count);
                    byteArr = newbuf;
                }

                System.arraycopy(buffer, 0, byteArr, count, len);
                count += len;
            }
        }

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options);

        ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);

        input.close();

        return rotateBitmap(b, orientation);

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

        return null;
    }
}

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

private Bitmap getPortraitImage(String imagePath) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;//ww w.j  av  a 2s  .c o  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.mobantica.DriverItRide.activities.ActivityProfile.java

private void previewCapturedImage() {
    try {// www  . j a v a  2s .c  o  m
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), ChnagedUri);
        if (bitmap != null) {
            ExifInterface ei = null;
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    InputStream in = getContentResolver().openInputStream(ChnagedUri);
                    ei = new ExifInterface(in);
                } else {
                    ei = new ExifInterface(ChnagedUri.getPath());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (ei != null) {
                int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_UNDEFINED);
                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    bitmap = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    bitmap = rotateImage(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    bitmap = rotateImage(bitmap, 270);
                    break;
                }
            }

            Bitmap imageBitmap;
            imageBitmap = Bitmap.createScaledBitmap(AppUtils.resizeAndCropCenter(bitmap, 250, true), 250, 250,
                    false);
            img_profile_square.setImageBitmap(imageBitmap);

            imagebaseProfilephoto = Generic.convertBitmapToByteStrem(imageBitmap);
            task = new ActivityProfile.UpdateProfilePhotoTask();
            task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
        }
    } catch (IOException e) {
        e.printStackTrace();
        //Set default image here
    }
}

From source file:com.klinker.android.twitter.activities.profile_viewer.ProfilePager.java

private Bitmap getBitmapToSend(Uri uri) throws FileNotFoundException, IOException {
    InputStream input = getContentResolver().openInputStream(uri);

    BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
    onlyBoundsOptions.inJustDecodeBounds = true;
    onlyBoundsOptions.inDither = true;//optional
    onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional
    BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
    input.close();/*  ww w.  ja va2  s. c o m*/
    if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
        return null;

    int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight
            : onlyBoundsOptions.outWidth;

    double ratio = (originalSize > 1000) ? (originalSize / 1000) : 1.0;

    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio);
    bitmapOptions.inDither = true;//optional
    bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
    input = this.getContentResolver().openInputStream(uri);
    Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);

    ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

    input.close();

    return bitmap;
}

From source file:im.vector.activity.RoomActivity.java

/**
 *
 *//*from   ww  w .  j  ava  2  s  .  c o  m*/
private void manageSendMoreButtons() {
    boolean hasText = mEditText.getText().length() > 0;
    boolean hasPreviewedMedia = (null != mPendingThumbnailUrl);

    if (hasPreviewedMedia) {
        mMediasCache.loadBitmap(mImagePreviewView, mPendingThumbnailUrl, 0, ExifInterface.ORIENTATION_UNDEFINED,
                mPendingMimeType);
    }

    mImagePreviewLayout.setVisibility(hasPreviewedMedia ? View.VISIBLE : View.GONE);
    mEditText.setVisibility(hasPreviewedMedia ? View.INVISIBLE : View.VISIBLE);

    mSendButton.setVisibility((hasText || hasPreviewedMedia) ? View.VISIBLE : View.INVISIBLE);
    mAttachmentButton.setVisibility((hasText || hasPreviewedMedia) ? View.INVISIBLE : View.VISIBLE);
}

From source file:com.klinker.android.twitter.ui.profile_viewer.ProfilePager.java

private Bitmap getBitmapToSend(Uri uri) throws FileNotFoundException, IOException {
    InputStream input = getContentResolver().openInputStream(uri);

    BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
    onlyBoundsOptions.inJustDecodeBounds = true;
    onlyBoundsOptions.inDither = true;//optional
    onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional
    BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
    input.close();/*from   w  w w  .  j  a va 2s.c  om*/
    if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
        return null;

    int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight
            : onlyBoundsOptions.outWidth;

    double ratio = (originalSize > 500) ? (originalSize / 500) : 1.0;

    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio);
    bitmapOptions.inDither = true;//optional
    bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
    input = this.getContentResolver().openInputStream(uri);
    Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);

    ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

    input.close();

    return rotateBitmap(bitmap, orientation);
}

From source file:org.matrix.console.activity.RoomActivity.java

/**
 *
 *///from w  w  w . j a v a 2s.  co  m
private void manageSendMoreButtons() {
    boolean hasText = mEditText.getText().length() > 0;
    boolean hasPreviewedMedia = (null != mPendingThumbnailUrl);

    if (hasPreviewedMedia) {
        mMediasCache.loadBitmap(mSession.getHomeserverConfig(), mImagePreviewView, mPendingThumbnailUrl, 0,
                ExifInterface.ORIENTATION_UNDEFINED, mPendingMimeType);
    }

    mImagePreviewLayout.setVisibility(hasPreviewedMedia ? View.VISIBLE : View.GONE);
    mEditText.setVisibility(hasPreviewedMedia ? View.INVISIBLE : View.VISIBLE);

    mSendButton.setVisibility((hasText || hasPreviewedMedia) ? View.VISIBLE : View.INVISIBLE);
    mAttachmentButton.setVisibility((hasText || hasPreviewedMedia) ? View.INVISIBLE : View.VISIBLE);
}

From source file:org.exoplatform.utils.ExoDocumentUtils.java

/**
 * Get the EXIF orientation of the given file
 * //from   w  ww .  j a  va 2s  . co m
 * @param filePath
 * @return an int in ExoDocumentUtils.ROTATION_[0 , 90 , 180 , 270]
 */
public static int getExifOrientationAngleFromFile(String filePath) {
    int ret = ROTATION_0;
    try {
        ret = new ExifInterface(filePath).getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);
        switch (ret) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            ret = ROTATION_90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            ret = ROTATION_180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            ret = ROTATION_270;
            break;
        default:
            break;
        }
    } catch (IOException e) {
        if (Log.LOGD)
            Log.d(ExoDocumentUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
    }
    return ret;
}