android.media.ExifInterface Java Examples

The following examples show how to use android.media.ExifInterface. 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: Fetcher.java    From tns-core-modules-widgets with Apache License 2.0 8 votes vote down vote up
public static Bitmap decodeSampledBitmapFromByteArray(byte[] buffer, int reqWidth, int reqHeight,
        boolean keepAspectRatio, Cache cache) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(buffer, 0, buffer.length, options);

    options.inSampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;

    // If we're running on Honeycomb or newer, try to use inBitmap
    if (Utils.hasHoneycomb()) {
        addInBitmapOptions(options, cache);
    }

    final Bitmap bitmap = BitmapFactory.decodeByteArray(buffer, 0, buffer.length, options);

    InputStream is = new ByteArrayInputStream(buffer);
    ExifInterface ei = getExifInterface(is);

    return scaleAndRotateBitmap(bitmap, ei, reqWidth, reqHeight, keepAspectRatio);
}
 
Example #2
Source File: ImageUtil.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 获取拍照后旋转角度
 * */
public static int readPictureDegree(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;
}
 
Example #3
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
public static int getRotateDegree(final String filePath) {
    try {
        ExifInterface exifInterface = new ExifInterface(filePath);
        int orientation = exifInterface.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL
        );
        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;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return -1;
    }
}
 
Example #4
Source File: BitmapUtil.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据path
 *
 * @param path
 * @return
 */
public final static int getDegress(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;
}
 
Example #5
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 #6
Source File: ResizeAndRotateProducerTest.java    From fresco with MIT License 6 votes vote down vote up
private void testDoesRotateIfJpegAndCannotDeferRotation() throws Exception {
  int rotationAngle = 180;
  int exifOrientation = ExifInterface.ORIENTATION_ROTATE_180;
  int sourceWidth = 10;
  int sourceHeight = 10;
  whenRequestWidthAndHeight(sourceWidth, sourceHeight);
  whenRequestsRotationFromMetadataWithoutDeferring();

  provideIntermediateResult(
      DefaultImageFormats.JPEG, sourceWidth, sourceHeight, rotationAngle, exifOrientation);
  verifyNoIntermediateResultPassedThrough();

  provideFinalResult(
      DefaultImageFormats.JPEG, sourceWidth, sourceHeight, rotationAngle, exifOrientation);
  verifyAFinalResultPassedThroughNotResized();

  assertEquals(2, mFinalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
  assertTrue(mPooledByteBuffer.isClosed());

  verifyJpegTranscoderInteractions(8, rotationAngle);
}
 
Example #7
Source File: PhotoUtils.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片的旋转角度
 *
 * @param path 图片的绝对路径
 * @return 图片的旋转角度
 */
private int getBitmapDegree(String path) {
    int degree = 0;
    try {
        // 从指定路径下读取图片,并获取其EXIF信息
        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;
}
 
Example #8
Source File: ImageUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Return the rotated degree.
 *
 * @param filePath The path of file.
 * @return the rotated degree
 */
public static int getRotateDegree(final String filePath) {
    try {
        ExifInterface exifInterface = new ExifInterface(filePath);
        int orientation = exifInterface.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL
        );
        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;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return -1;
    }
}
 
Example #9
Source File: BitmapUtil.java    From Matisse with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片的旋转角度
 *
 * @param path 图片绝对路径
 * @return 图片的旋转角度
 */
public static int getBitmapDegree(String path) {
    int degree = 0;
    try {
        // 从指定路径下读取图片,并获取其EXIF信息
        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;
}
 
Example #10
Source File: MediaDetails.java    From medialibrary with Apache License 2.0 6 votes vote down vote up
public static void extractExifInfo(MediaDetails details, String filePath) {
    try {
        ExifInterface exif = new ExifInterface(filePath);
        setExifData(details, exif, ExifInterface.TAG_FLASH, MediaDetails.INDEX_FLASH);
        setExifData(details, exif, ExifInterface.TAG_IMAGE_WIDTH, MediaDetails.INDEX_WIDTH);
        setExifData(details, exif, ExifInterface.TAG_IMAGE_LENGTH,
                MediaDetails.INDEX_HEIGHT);
        setExifData(details, exif, ExifInterface.TAG_MAKE, MediaDetails.INDEX_MAKE);
        setExifData(details, exif, ExifInterface.TAG_MODEL, MediaDetails.INDEX_MODEL);
        setExifData(details, exif, ExifInterface.TAG_APERTURE, MediaDetails.INDEX_APERTURE);
        setExifData(details, exif, ExifInterface.TAG_ISO, MediaDetails.INDEX_ISO);
        setExifData(details, exif, ExifInterface.TAG_WHITE_BALANCE,
                MediaDetails.INDEX_WHITE_BALANCE);
        setExifData(details, exif, ExifInterface.TAG_EXPOSURE_TIME,
                MediaDetails.INDEX_EXPOSURE_TIME);
        double data = exif.getAttributeDouble(ExifInterface.TAG_FOCAL_LENGTH, 0);
        if (data != 0f) {
            details.addDetail(MediaDetails.INDEX_FOCAL_LENGTH, data);
            details.setUnit(MediaDetails.INDEX_FOCAL_LENGTH, R.string.unit_mm);
        }
    } catch (IOException ex) {
        // ignore it.
        Log.w(TAG, "", ex);
    }
}
 
Example #11
Source File: CompressEngine.java    From FastAndroid with Apache License 2.0 6 votes vote down vote up
private Bitmap rotatingImage(Bitmap bitmap) {
    if (srcExif == null) return bitmap;

    Matrix matrix = new Matrix();
    int angle = 0;
    int orientation = srcExif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            angle = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            angle = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            angle = 270;
            break;
    }

    matrix.postRotate(angle);

    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
 
Example #12
Source File: PhotoUtil.java    From Conquer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * 读取图片属性:旋转的角度
 * 
 * @param path
 *            图片绝对路径
 * @return degree旋转的角度
 */

public static int readPictureDegree(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;

}
 
Example #13
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 #14
Source File: ExifHelper.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
/**
 * Reads all the EXIF data from the input file.
 */
public void readExifData() {
    this.aperture = inFile.getAttribute(ExifInterface.TAG_APERTURE);
    this.datetime = inFile.getAttribute(ExifInterface.TAG_DATETIME);
    this.exposureTime = inFile.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
    this.flash = inFile.getAttribute(ExifInterface.TAG_FLASH);
    this.focalLength = inFile.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    this.gpsAltitude = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
    this.gpsAltitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF);
    this.gpsDateStamp = inFile.getAttribute(ExifInterface.TAG_GPS_DATESTAMP);
    this.gpsLatitude = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
    this.gpsLatitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
    this.gpsLongitude = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    this.gpsLongitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
    this.gpsProcessingMethod = inFile.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD);
    this.gpsTimestamp = inFile.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
    this.iso = inFile.getAttribute(ExifInterface.TAG_ISO);
    this.make = inFile.getAttribute(ExifInterface.TAG_MAKE);
    this.model = inFile.getAttribute(ExifInterface.TAG_MODEL);
    this.orientation = inFile.getAttribute(ExifInterface.TAG_ORIENTATION);
    this.whiteBalance = inFile.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
}
 
Example #15
Source File: ClipImageActivity.java    From clip-image with Apache License 2.0 6 votes vote down vote up
/**
 * 读取图片属性:旋转的角度
 *
 * @param path 图片绝对路径
 * @return degree旋转的角度
 */
public static int readPictureDegree(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;
}
 
Example #16
Source File: ExifHelper.java    From wildfly-samples with MIT License 6 votes vote down vote up
/**
 * Reads all the EXIF data from the input file.
 */
public void readExifData() {
    this.aperture = inFile.getAttribute(ExifInterface.TAG_APERTURE);
    this.datetime = inFile.getAttribute(ExifInterface.TAG_DATETIME);
    this.exposureTime = inFile.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
    this.flash = inFile.getAttribute(ExifInterface.TAG_FLASH);
    this.focalLength = inFile.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    this.gpsAltitude = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
    this.gpsAltitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF);
    this.gpsDateStamp = inFile.getAttribute(ExifInterface.TAG_GPS_DATESTAMP);
    this.gpsLatitude = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
    this.gpsLatitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
    this.gpsLongitude = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    this.gpsLongitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
    this.gpsProcessingMethod = inFile.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD);
    this.gpsTimestamp = inFile.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
    this.iso = inFile.getAttribute(ExifInterface.TAG_ISO);
    this.make = inFile.getAttribute(ExifInterface.TAG_MAKE);
    this.model = inFile.getAttribute(ExifInterface.TAG_MODEL);
    this.orientation = inFile.getAttribute(ExifInterface.TAG_ORIENTATION);
    this.whiteBalance = inFile.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
}
 
Example #17
Source File: ImageUtils.java    From Common with Apache License 2.0 6 votes vote down vote up
public static int getImageDegree(String filename) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(filename);
        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 (Throwable e) {
        e.printStackTrace();
    }
    return degree;
}
 
Example #18
Source File: Engine.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private Bitmap rotatingImage(Bitmap bitmap) {
  if (mSourceExif == null) return bitmap;

  Matrix matrix = new Matrix();
  int angle = 0;
  int orientation = mSourceExif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
      angle = 90;
      break;
    case ExifInterface.ORIENTATION_ROTATE_180:
      angle = 180;
      break;
    case ExifInterface.ORIENTATION_ROTATE_270:
      angle = 270;
      break;
  }

  matrix.postRotate(angle);

  return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
 
Example #19
Source File: ResizeAndRotateProducerTest.java    From fresco with MIT License 6 votes vote down vote up
@Test
public void testDoesNotRotateIfCanDeferRotationAndResizeNotNeeded() throws Exception {
  whenResizingEnabled();

  int rotationAngle = 180;
  int exifOrientation = ExifInterface.ORIENTATION_ROTATE_180;
  int sourceWidth = 10;
  int sourceHeight = 10;
  whenRequestWidthAndHeight(sourceWidth, sourceHeight);
  whenRequestsRotationFromMetadataWithDeferringAllowed();

  provideIntermediateResult(
      DefaultImageFormats.JPEG, sourceWidth, sourceHeight, rotationAngle, exifOrientation);
  verifyIntermediateResultPassedThroughUnchanged();

  provideFinalResult(
      DefaultImageFormats.JPEG, sourceWidth, sourceHeight, rotationAngle, exifOrientation);
  verifyFinalResultPassedThroughUnchanged();

  verifyZeroJpegTranscoderInteractions();
}
 
Example #20
Source File: PhotoUtil.java    From LoveTalkClient with Apache License 2.0 6 votes vote down vote up
/**
 * 读取图片属性:旋转的角度
 *
 * @param path 图片绝对路径
 * @return degree旋转的角度
 */

public static int readPictureDegree(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;

}
 
Example #21
Source File: ExifHelper.java    From reader with MIT License 6 votes vote down vote up
/**
 * Reads all the EXIF data from the input file.
 */
public void readExifData() {
    this.aperture = inFile.getAttribute(ExifInterface.TAG_APERTURE);
    this.datetime = inFile.getAttribute(ExifInterface.TAG_DATETIME);
    this.exposureTime = inFile.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
    this.flash = inFile.getAttribute(ExifInterface.TAG_FLASH);
    this.focalLength = inFile.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    this.gpsAltitude = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
    this.gpsAltitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF);
    this.gpsDateStamp = inFile.getAttribute(ExifInterface.TAG_GPS_DATESTAMP);
    this.gpsLatitude = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
    this.gpsLatitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
    this.gpsLongitude = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    this.gpsLongitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
    this.gpsProcessingMethod = inFile.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD);
    this.gpsTimestamp = inFile.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
    this.iso = inFile.getAttribute(ExifInterface.TAG_ISO);
    this.make = inFile.getAttribute(ExifInterface.TAG_MAKE);
    this.model = inFile.getAttribute(ExifInterface.TAG_MODEL);
    this.orientation = inFile.getAttribute(ExifInterface.TAG_ORIENTATION);
    this.whiteBalance = inFile.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
}
 
Example #22
Source File: BitmapUtils.java    From timecat 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 #23
Source File: JpegTranscoderUtils.java    From fresco with MIT License 6 votes vote down vote up
/** @return true if and only if given value is a valid EXIF orientation */
public static boolean isExifOrientationAllowed(int exifOrientation) {
  switch (exifOrientation) {
    case ExifInterface.ORIENTATION_NORMAL:
    case ExifInterface.ORIENTATION_ROTATE_90:
    case ExifInterface.ORIENTATION_ROTATE_180:
    case ExifInterface.ORIENTATION_ROTATE_270:
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
    case ExifInterface.ORIENTATION_TRANSPOSE:
    case ExifInterface.ORIENTATION_TRANSVERSE:
      return true;
    default:
      return false;
  }
}
 
Example #24
Source File: ExifHelper.java    From reader with MIT License 6 votes vote down vote up
/**
 * Reads all the EXIF data from the input file.
 */
public void readExifData() {
    this.aperture = inFile.getAttribute(ExifInterface.TAG_APERTURE);
    this.datetime = inFile.getAttribute(ExifInterface.TAG_DATETIME);
    this.exposureTime = inFile.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
    this.flash = inFile.getAttribute(ExifInterface.TAG_FLASH);
    this.focalLength = inFile.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    this.gpsAltitude = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
    this.gpsAltitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF);
    this.gpsDateStamp = inFile.getAttribute(ExifInterface.TAG_GPS_DATESTAMP);
    this.gpsLatitude = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
    this.gpsLatitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
    this.gpsLongitude = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    this.gpsLongitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
    this.gpsProcessingMethod = inFile.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD);
    this.gpsTimestamp = inFile.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
    this.iso = inFile.getAttribute(ExifInterface.TAG_ISO);
    this.make = inFile.getAttribute(ExifInterface.TAG_MAKE);
    this.model = inFile.getAttribute(ExifInterface.TAG_MODEL);
    this.orientation = inFile.getAttribute(ExifInterface.TAG_ORIENTATION);
    this.whiteBalance = inFile.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
}
 
Example #25
Source File: BitmapUtils.java    From AlbumCameraRecorder with MIT License 6 votes vote down vote up
/**
 * 获取图片的旋转角度
 *
 * @param path 图片绝对路径
 * @return 图片的旋转角度
 */
public static int getBitmapDegree(String path) {
    int degree = 0;
    try {
        // 从指定路径下读取图片,并获取其EXIF信息
        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;
}
 
Example #26
Source File: FileUtilsJ.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get degree from exif
 */
public static int readPictureDegree(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) {
        LogUtil.e(e.getMessage());
    }
    return degree;
}
 
Example #27
Source File: MediaUtils.java    From q-municate-android with Apache License 2.0 6 votes vote down vote up
/**
 * Allows to fix issue for some phones when image processed with android-crop
 * is not rotated properly.
 * Should be used in non-UI thread.
 */
public static void normalizeRotationImageIfNeed(File file) {
    Context context = App.getInstance().getApplicationContext();
    String filePath = file.getPath();
    Uri uri = getValidUri(file, context);
    try {
        ExifInterface exif = new ExifInterface(filePath);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
        Bitmap rotatedBitmap = rotateBitmap(bitmap, orientation);
        if (!bitmap.equals(rotatedBitmap)) {
            saveBitmapToFile(context, rotatedBitmap, uri);
        }
    } catch (Exception e) {
        ErrorUtils.logError("Exception:", e.getMessage());
    }
}
 
Example #28
Source File: OrientedDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
public int getIntrinsicWidth() {
  if (mExifOrientation == ExifInterface.ORIENTATION_TRANSPOSE
      || mExifOrientation == ExifInterface.ORIENTATION_TRANSVERSE
      || mRotationAngle % 180 != 0) {
    return super.getIntrinsicHeight();
  } else {
    return super.getIntrinsicWidth();
  }
}
 
Example #29
Source File: ExifHelper.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
public int getOrientation() {
    int o = Integer.parseInt(this.orientation);

    if (o == ExifInterface.ORIENTATION_NORMAL) {
        return 0;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_90) {
        return 90;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_180) {
        return 180;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_270) {
        return 270;
    } else {
        return 0;
    }
}
 
Example #30
Source File: CropUtil.java    From ImageChoose with MIT License 5 votes vote down vote up
public static boolean copyExifRotation(File sourceFile, File destFile) {
    if (sourceFile == null || destFile == null) return false;
    try {
        ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
        ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
        exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
        exifDest.saveAttributes();
        return true;
    } catch (IOException e) {
        CLog.e("Error copying Exif data" + e.getMessage());
        return false;
    }
}