Java Code Examples for android.support.media.ExifInterface#ORIENTATION_ROTATE_270

The following examples show how to use android.support.media.ExifInterface#ORIENTATION_ROTATE_270 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapUtils.java    From giffun with Apache License 2.0 6 votes vote down vote up
/**
 * Rotate the given image by given Exif value.<br>
 * If no rotation is required the image will not be rotated.<br>
 * New bitmap is created and the old one is recycled.
 */
static RotateBitmapResult rotateBitmapByExif(Bitmap bitmap, ExifInterface exif) {
  int degrees;
  int orientation =
      exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  switch (orientation) {
    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;
  }
  return new RotateBitmapResult(bitmap, degrees);
}
 
Example 2
Source File: TagSettings.java    From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public int getCameraPhotoOrientation(Uri file){
    int rotate = 0;
    try (InputStream inputStream = getApplicationContext().getContentResolver().openInputStream(file)) {
        ExifInterface exif = new ExifInterface(inputStream);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
        }
    } catch (Exception e) {
        Log.e(TAG, "Could not get orientation of image");
    }
    return rotate;
}
 
Example 3
Source File: ExifUtil.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
public static int getExifOrientationAngle(Context context, AlbumItem albumItem) {
    ExifInterface exif = getExifInterface(context, albumItem);
    if (exif == null) {
        return 0;
    }
    int orientation = (int) getCastValue(exif, ExifInterface.TAG_ORIENTATION);
    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return 0;
    }
}
 
Example 4
Source File: PostProcessor.java    From camerakit-android with MIT License 6 votes vote down vote up
public boolean areDimensionsFlipped() {
    switch (orientation) {
        case ExifInterface.ORIENTATION_TRANSPOSE:
        case ExifInterface.ORIENTATION_ROTATE_90:
        case ExifInterface.ORIENTATION_TRANSVERSE:
        case ExifInterface.ORIENTATION_ROTATE_270:
            return true;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        case ExifInterface.ORIENTATION_ROTATE_180:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        case ExifInterface.ORIENTATION_NORMAL:
        case ExifInterface.ORIENTATION_UNDEFINED:
            return false;
    }

    return false;
}
 
Example 5
Source File: ImageUtil.java    From Learning-Resources with MIT License 6 votes vote down vote up
/**
 * Does the same as {@link #isPictureValidForUpload(Uri)} but takes a file path instead of an
 * Uri.
 *
 * @param filePath The path to the image.
 * @throws IOException Thrown if the file cannot be found.
 */
public boolean isPictureValidForUpload(final String filePath) throws IOException {
    BitmapFactory.Options opts = getImageDimensions(filePath);
    ExifInterface exif = new ExifInterface(filePath);
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
            ExifInterface.ORIENTATION_NORMAL);

    // Translate the orientation constant to degrees.
    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            orientation = 90;
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            orientation = 270;
            break;

        default:
            break;
    }

    return isPictureDimensionsValid(opts.outWidth, opts.outHeight, orientation);
}
 
Example 6
Source File: Util.java    From CVScanner with GNU General Public License v3.0 6 votes vote down vote up
public static int getExifRotation(Context context, Uri imageUri) throws IOException {
    if (imageUri == null) return 0;
    InputStream inputStream = null;
    try {
        inputStream = context.getContentResolver().openInputStream(imageUri);
        ExifInterface exifInterface = new ExifInterface(inputStream);
        // We only recognize a subset of orientation tag values
        switch (exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                return 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return 270;
            default:
                return ExifInterface.ORIENTATION_UNDEFINED;
        }
    }finally {
        closeSilently(inputStream);
    }
}
 
Example 7
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static int getImageOrientation(String imagePath) {
    int rotate = 0;
    try {
        ExifInterface exif = new ExifInterface(imagePath);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return rotate;
}
 
Example 8
Source File: PostProcessor.java    From camerakit-android with MIT License 5 votes vote down vote up
public void apply(JpegTransformer transformer) {
    switch (orientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            transformer.flipHorizontal();
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            transformer.rotate(180);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            transformer.flipVertical();
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            transformer.rotate(90);
            transformer.flipHorizontal();
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            transformer.rotate(90);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            transformer.rotate(270);
            transformer.flipHorizontal();
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            transformer.rotate(90);
            break;
        case ExifInterface.ORIENTATION_NORMAL:
        case ExifInterface.ORIENTATION_UNDEFINED:
            break;
    }
}
 
Example 9
Source File: Util.java    From CVScanner with GNU General Public License v3.0 5 votes vote down vote up
public static boolean setExifRotation(Context context, Uri imageUri, int rotation) throws IOException {
    if (imageUri == null) return false;

    InputStream destStream = null;
    try{
        destStream = context.getContentResolver().openInputStream(imageUri);

        ExifInterface exif = new ExifInterface(destStream);

        exif.setAttribute("UserComment", "Generated using CVScanner");

        int orientation = ExifInterface.ORIENTATION_NORMAL;
        switch (rotation){
            case 1:
                orientation = ExifInterface.ORIENTATION_ROTATE_90;
                break;

            case 2:
                orientation = ExifInterface.ORIENTATION_ROTATE_180;
                break;

            case 3:
                orientation = ExifInterface.ORIENTATION_ROTATE_270;
                break;
        }
        exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(orientation));
        exif.saveAttributes();
    }finally {
        closeSilently(destStream);
    }
    return true;
}
 
Example 10
Source File: ImageUpdater.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 13) {
            PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
            int orientation = 0;
            try {
                ExifInterface ei = new ExifInterface(currentPicturePath);
                int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                switch (exif) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        orientation = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        orientation = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        orientation = 270;
                        break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            final ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false));
            PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 1, new PhotoViewer.EmptyPhotoViewerProvider() {
                @Override
                public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
                    String path = null;
                    MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
                    if (photoEntry.imagePath != null) {
                        path = photoEntry.imagePath;
                    } else if (photoEntry.path != null) {
                        path = photoEntry.path;
                    }
                    Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
                    processBitmap(bitmap);
                }

                @Override
                public boolean allowCaption() {
                    return false;
                }

                @Override
                public boolean canScrollAway() {
                    return false;
                }
            }, null);
            AndroidUtilities.addMediaToGallery(currentPicturePath);
            currentPicturePath = null;
        } else if (requestCode == 14) {
            if (data == null || data.getData() == null) {
                return;
            }
            startCrop(null, data.getData());
        }
    }
}
 
Example 11
Source File: ImageUpdater.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 13) {
            PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
            int orientation = 0;
            try {
                ExifInterface ei = new ExifInterface(currentPicturePath);
                int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                switch (exif) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        orientation = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        orientation = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        orientation = 270;
                        break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            final ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false));
            PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 1, new PhotoViewer.EmptyPhotoViewerProvider() {
                @Override
                public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
                    String path = null;
                    MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
                    if (photoEntry.imagePath != null) {
                        path = photoEntry.imagePath;
                    } else if (photoEntry.path != null) {
                        path = photoEntry.path;
                    }
                    Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
                    processBitmap(bitmap);
                }

                @Override
                public boolean allowCaption() {
                    return false;
                }

                @Override
                public boolean canScrollAway() {
                    return false;
                }
            }, null);
            AndroidUtilities.addMediaToGallery(currentPicturePath);
            currentPicturePath = null;
        } else if (requestCode == 14) {
            if (data == null || data.getData() == null) {
                return;
            }
            startCrop(null, data.getData());
        }
    }
}
 
Example 12
Source File: LoadedImage.java    From edslite with GNU General Public License v2.0 4 votes vote down vote up
private void loadInitOrientation(Path imagePath)
{
    try
    {
        InputStream s = imagePath.getFile().getInputStream();
        try
        {
            Metadata m = ImageMetadataReader.readMetadata(s);

            for(Directory directory: m.getDirectories())
                if(directory.containsTag(ExifSubIFDDirectory.TAG_ORIENTATION))
                {
                    int orientation = directory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION);
                    switch (orientation)
                    {
                        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_180:
                            _rotation = 180;
                            break;
                        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                            _rotation = 180;
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_TRANSPOSE:
                            _rotation = 90;
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_90:
                            _rotation = 90;
                            break;
                        case ExifInterface.ORIENTATION_TRANSVERSE:
                            _rotation = -90;
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_270:
                            _rotation = -90;
                            break;
                    }
                    break;
                }
        }
        finally
        {
            s.close();
        }
    }
    catch (Exception e)
    {
        if(GlobalConfig.isDebug())
            Logger.log(e);
    }
}
 
Example 13
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
public static Bitmap getThumbnailFile(Context context, Uri uri, int thumbnailSize) throws IOException {

        InputStream is = openInputStream(context, uri);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inInputShareable = true;
        options.inPurgeable = true;
        
        BitmapFactory.decodeStream(is, null, options);
        
        if ((options.outWidth == -1) || (options.outHeight == -1))
            return null;

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

        is.close();
        is = openInputStream(context, uri);

        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = calculateInSampleSize(options, thumbnailSize, thumbnailSize);

        Bitmap scaledBitmap = BitmapFactory.decodeStream(is, null, opts);
        is.close();

        InputStream isEx = openInputStream(context,uri);
        ExifInterface exif = new ExifInterface(isEx);
        int orientationType = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int orientationD  = 0;
        if (orientationType == ExifInterface.ORIENTATION_ROTATE_90)
            orientationD = 90;
        else if (orientationType == ExifInterface.ORIENTATION_ROTATE_180)
            orientationD = 180;
        else if (orientationType == ExifInterface.ORIENTATION_ROTATE_270)
            orientationD = 270;

        if (orientationD != 0)
            scaledBitmap = rotateBitmap(scaledBitmap, orientationD);

        isEx.close();

        return scaledBitmap;
    }