Java Code Examples for android.media.ExifInterface#ORIENTATION_UNDEFINED

The following examples show how to use android.media.ExifInterface#ORIENTATION_UNDEFINED . 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: CropUtil.java    From LockDemo with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        Log.e("Error getting Exif data", e);
        return 0;
    }
}
 
Example 2
Source File: CropUtil.java    From ImagePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片旋转角度
 *
 * @param path 图片路径
 * @return 旋转角度
 */
public static int getExifRotation(String path)
{
    if (TextUtils.isEmpty(path))
        return 0;

    try
    {
        ExifInterface exif = new ExifInterface(path);
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e)
    {
        return 0;
    }
}
 
Example 3
Source File: CropUtil.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        Log.e("Error getting Exif data", e);
        return 0;
    }
}
 
Example 4
Source File: CropUtil.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        Log.e("Error getting Exif data", e);
        return 0;
    }
}
 
Example 5
Source File: CropUtil.java    From CloudPan with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        Log.e("Error getting Exif data", e);
        return 0;
    }
}
 
Example 6
Source File: CropUtil.java    From HaiNaBaiChuan with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        Log.e("Error getting Exif data", e);
        return 0;
    }
}
 
Example 7
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieve the image orientation from the Exif data of an image.
 *
 * @param path The file path of the image
 * @return the orientation stored in the exif data.
 */
private static int getExifOrientation(@NonNull final String path) {
	try {
		ExifInterface exif = new ExifInterface(path);
		int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

		if (orientation == ExifInterface.ORIENTATION_UNDEFINED) {
			// Use custom implementation, as the previous one is not always reliable
			orientation = JpegMetadataUtil.getExifOrientation(new File(path));
		}

		return orientation;
	}
	catch (Exception e) {
		Log.w(Application.TAG, "Exception when getting EXIF rotation");
		return ExifInterface.ORIENTATION_NORMAL;
	}
}
 
Example 8
Source File: CropUtil.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        return 0;
    }
}
 
Example 9
Source File: CropUtil.java    From GalleryFinal with Apache License 2.0 6 votes vote down vote up
public static int getExifRotation(File imageFile) {
    if (imageFile == null) return 0;
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.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;
        }
    } catch (IOException e) {
        ILogger.e(e);
        return 0;
    }
}
 
Example 10
Source File: ImageUtils.java    From image-intent-handler with Apache License 2.0 5 votes vote down vote up
public static String getRightAngleImage(String photoPath) {
    try {
        ExifInterface ei = new ExifInterface(photoPath);
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int degree;
        switch (orientation) {
            case ExifInterface.ORIENTATION_NORMAL:
                degree = 0;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
            case ExifInterface.ORIENTATION_UNDEFINED:
                degree = 0;
                break;
            default:
                degree = 90;
        }
        return rotateImage(degree, photoPath);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return photoPath;
}
 
Example 11
Source File: JfifUtil.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Get orientation information from jpeg input stream.
 *
 * @param is the input stream of jpeg image
 * @return orientation: 1/8/3/6. Returns {@value
 *     android.media.ExifInterface#ORIENTATION_UNDEFINED} if there is no valid orientation
 *     information.
 */
public static int getOrientation(InputStream is) {
  try {
    int length = moveToAPP1EXIF(is);
    if (length == 0) {
      return ExifInterface.ORIENTATION_UNDEFINED;
    }
    return TiffUtil.readOrientationFromTIFF(is, length);
  } catch (IOException ioe) {
    return ExifInterface.ORIENTATION_UNDEFINED;
  }
}
 
Example 12
Source File: TiffUtil.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Determines auto-rotate angle based on orientation information.
 *
 * @param orientation orientation information read from APP1 EXIF (TIFF) block.
 * @return orientation: 1/3/6/8 -> 0/180/90/270. Returns 0 for inverted orientations (2/4/5/7).
 */
public static int getAutoRotateAngleFromOrientation(int orientation) {
  switch (orientation) {
    case ExifInterface.ORIENTATION_NORMAL:
    case ExifInterface.ORIENTATION_UNDEFINED:
      return 0;
    case ExifInterface.ORIENTATION_ROTATE_180:
      return 180;
    case ExifInterface.ORIENTATION_ROTATE_90:
      return 90;
    case ExifInterface.ORIENTATION_ROTATE_270:
      return 270;
  }
  return 0;
}
 
Example 13
Source File: HeifExifUtil.java    From fresco with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N)
static int getOrientation(final InputStream inputStream) {
  try {
    final ExifInterface exifInterface = new ExifInterface(inputStream);
    return exifInterface.getAttributeInt(
        ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  } catch (final IOException e) {
    FLog.d(TAG, "Failed reading Heif Exif orientation -> ignoring", e);
    return ExifInterface.ORIENTATION_UNDEFINED;
  }
}
 
Example 14
Source File: JpegMetadataUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieve the orientation of a file from the EXIF data. Required, as built-in ExifInterface is not always
 * reliable.
 *
 * @param imageFile the image file.
 * @return the orientation value.
 */
protected static int getExifOrientation(@NonNull final File imageFile) {
	try {
		final IImageMetadata metadata = Imaging.getMetadata(imageFile);
		TiffImageMetadata tiffImageMetadata;

		if (metadata instanceof JpegImageMetadata) {
			tiffImageMetadata = ((JpegImageMetadata) metadata).getExif();
		}
		else if (metadata instanceof TiffImageMetadata) {
			tiffImageMetadata = (TiffImageMetadata) metadata;
		}
		else {
			return ExifInterface.ORIENTATION_UNDEFINED;
		}

		TiffField field = tiffImageMetadata.findField(TiffTagConstants.TIFF_TAG_ORIENTATION);
		if (field != null) {
			return field.getIntValue();
		}
		else {
			TagInfo tagInfo = new TagInfoShort("Orientation", 274, 1, TiffDirectoryType.TIFF_DIRECTORY_IFD0); // MAGIC_NUMBER
			field = tiffImageMetadata.findField(tagInfo);
			if (field != null) {
				return field.getIntValue();
			}
			else {
				return ExifInterface.ORIENTATION_UNDEFINED;
			}
		}
	}
	catch (Exception e) {
		return ExifInterface.ORIENTATION_UNDEFINED;
	}
}
 
Example 15
Source File: CloseableBitmapTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  mCloseableStaticBitmap =
      new CloseableStaticBitmap(
          mBitmap,
          mResourceReleaser,
          ImmutableQualityInfo.FULL_QUALITY,
          0,
          ExifInterface.ORIENTATION_UNDEFINED);
}
 
Example 16
Source File: Utils.java    From Android-CropView with Apache License 2.0 5 votes vote down vote up
public static Matrix getMatrixFromExifOrientation(int orientation) {
    Matrix matrix = new Matrix();
    switch (orientation) {
        case ExifInterface.ORIENTATION_UNDEFINED:
            break;
        case ExifInterface.ORIENTATION_NORMAL:
            break;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.postScale(-1.0f, 1.0f);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.postRotate(180.0f);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            matrix.postScale(1.0f, -1.0f);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.postRotate(90.0f);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            matrix.postRotate(-90.0f);
            matrix.postScale(1.0f, -1.0f);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            matrix.postRotate(90.0f);
            matrix.postScale(1.0f, -1.0f);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.postRotate(-90.0f);
            break;
    }
    return matrix;
}
 
Example 17
Source File: BitmapLoadUtils.java    From Matisse-Kotlin with Apache License 2.0 5 votes vote down vote up
public static int getExifOrientation(@NonNull Context context, @NonNull Uri imageUri) {
    int orientation = ExifInterface.ORIENTATION_UNDEFINED;
    try {
        InputStream stream = context.getContentResolver().openInputStream(imageUri);
        if (stream == null) {
            return orientation;
        }
        orientation = new ImageHeaderParser(stream).getOrientation();
        close(stream);
    } catch (IOException e) {
        Log.e(TAG, "getExifOrientation: " + imageUri.toString(), e);
    }
    return orientation;
}
 
Example 18
Source File: JpegTranscoderUtils.java    From fresco with MIT License 5 votes vote down vote up
public static int getSoftwareNumerator(
    RotationOptions rotationOptions,
    @Nullable ResizeOptions resizeOptions,
    EncodedImage encodedImage,
    boolean resizingEnabled) {
  if (!resizingEnabled) {
    return SCALE_DENOMINATOR;
  }
  if (resizeOptions == null) {
    return SCALE_DENOMINATOR;
  }

  final int rotationAngle = getRotationAngle(rotationOptions, encodedImage);
  int exifOrientation = ExifInterface.ORIENTATION_UNDEFINED;
  if (INVERTED_EXIF_ORIENTATIONS.contains(encodedImage.getExifOrientation())) {
    exifOrientation = getForceRotatedInvertedExifOrientation(rotationOptions, encodedImage);
  }

  final boolean swapDimensions =
      rotationAngle == 90
          || rotationAngle == 270
          || exifOrientation == ExifInterface.ORIENTATION_TRANSPOSE
          || exifOrientation == ExifInterface.ORIENTATION_TRANSVERSE;
  final int widthAfterRotation =
      swapDimensions ? encodedImage.getHeight() : encodedImage.getWidth();
  final int heightAfterRotation =
      swapDimensions ? encodedImage.getWidth() : encodedImage.getHeight();

  float ratio = determineResizeRatio(resizeOptions, widthAfterRotation, heightAfterRotation);
  int numerator = roundNumerator(ratio, resizeOptions.roundUpFraction);
  if (numerator > SCALE_DENOMINATOR) {
    return SCALE_DENOMINATOR;
  }
  return (numerator < 1) ? 1 : numerator;
}
 
Example 19
Source File: DefaultDrawableFactory.java    From fresco with MIT License 4 votes vote down vote up
private static boolean hasTransformableExifOrientation(
    CloseableStaticBitmap closeableStaticBitmap) {
  return closeableStaticBitmap.getExifOrientation() != ExifInterface.ORIENTATION_NORMAL
      && closeableStaticBitmap.getExifOrientation() != ExifInterface.ORIENTATION_UNDEFINED;
}
 
Example 20
Source File: CloseableStaticBitmap.java    From fresco with MIT License 2 votes vote down vote up
/**
 * Creates a new instance of a CloseableStaticBitmap from an existing CloseableReference. The
 * CloseableStaticBitmap will hold a reference to the Bitmap until it's closed.
 *
 * @param bitmapReference the bitmap reference.
 */
public CloseableStaticBitmap(
    CloseableReference<Bitmap> bitmapReference, QualityInfo qualityInfo, int rotationAngle) {
  this(bitmapReference, qualityInfo, rotationAngle, ExifInterface.ORIENTATION_UNDEFINED);
}