类android.media.ExifInterface源码实例Demo

下面列出了怎么用android.media.ExifInterface的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Tok-Android   文件: FileUtilsJ.java
/**
 * 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;
}
 
源代码2 项目: medialibrary   文件: MediaDetails.java
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);
    }
}
 
源代码3 项目: AndroidUtilCode   文件: ImageUtils.java
/**
 * 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;
    }
}
 
源代码4 项目: Android-utils   文件: ImageUtils.java
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;
    }
}
 
源代码5 项目: tysq-android   文件: BitmapUtil.java
/**
 * 根据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;
}
 
源代码6 项目: HaiNaBaiChuan   文件: CropUtil.java
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;
    }
}
 
源代码7 项目: bluemix-parking-meter   文件: ExifHelper.java
/**
 * 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);
}
 
源代码8 项目: tns-core-modules-widgets   文件: Fetcher.java
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);
}
 
源代码9 项目: q-municate-android   文件: MediaUtils.java
/**
 * 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());
    }
}
 
源代码10 项目: wildfly-samples   文件: ExifHelper.java
/**
 * 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);
}
 
源代码11 项目: Common   文件: ImageUtils.java
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;
}
 
源代码12 项目: fresco   文件: ResizeAndRotateProducerTest.java
@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();
}
 
源代码13 项目: timecat   文件: BitmapUtils.java
/**
 * 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);
}
 
源代码14 项目: reader   文件: ExifHelper.java
/**
 * 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);
}
 
源代码15 项目: Social   文件: ImageUtil.java
/**
 * 获取拍照后旋转角度
 * */
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;
}
 
源代码16 项目: AlbumCameraRecorder   文件: BitmapUtils.java
/**
 * 获取图片的旋转角度
 *
 * @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;
}
 
源代码17 项目: fresco   文件: JpegTranscoderUtils.java
/** @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;
  }
}
 
源代码18 项目: reader   文件: ExifHelper.java
/**
 * 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);
}
 
源代码19 项目: LoveTalkClient   文件: PhotoUtil.java
/**
 * 读取图片属性:旋转的角度
 *
 * @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;

}
 
源代码20 项目: phoenix   文件: Engine.java
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);
}
 
源代码21 项目: clip-image   文件: ClipImageActivity.java
/**
 * 读取图片属性:旋转的角度
 *
 * @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;
}
 
源代码22 项目: Conquer   文件: PhotoUtil.java
/**
 * 
 * 读取图片属性:旋转的角度
 * 
 * @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;

}
 
源代码23 项目: UltimateAndroid   文件: CropUtil.java
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;
    }
}
 
源代码24 项目: fresco   文件: ResizeAndRotateProducerTest.java
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);
}
 
源代码25 项目: MyBlogDemo   文件: PhotoUtils.java
/**
 * 获取图片的旋转角度
 *
 * @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;
}
 
源代码26 项目: Matisse   文件: BitmapUtil.java
/**
 * 获取图片的旋转角度
 *
 * @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;
}
 
源代码27 项目: FastAndroid   文件: CompressEngine.java
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);
}
 
源代码28 项目: Augendiagnose   文件: ImageUtil.java
/**
 * Convert the orientation as stored in EXIF metadata into degrees.
 *
 * @param exifOrientation The orientation as stored in the exif data.
 * @return the rotation in degrees.
 */
private static int convertExifOrientationToRotation(final int exifOrientation) {
	switch (exifOrientation) {
	case ExifInterface.ORIENTATION_ROTATE_270:
		return ROTATION_270;
	case ExifInterface.ORIENTATION_ROTATE_180:
		return ROTATION_180;
	case ExifInterface.ORIENTATION_ROTATE_90:
		return ROTATION_90;
	default:
		return 0;
	}
}
 
源代码29 项目: candybar   文件: BaseImageDecoder.java
protected ExifInfo defineExifOrientation(String imageUri) {
    int rotation = 0;
    boolean flip = false;
    try {
        ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                flip = true;
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
        }
    } catch (IOException e) {
        L.w("Can't read EXIF tags from file [%s]", imageUri);
    }
    return new ExifInfo(rotation, flip);
}
 
源代码30 项目: fresco   文件: OrientedDrawableTest.java
@Test
public void testCreation_transpose() {
  OrientedDrawable drawable =
      new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_TRANSPOSE);
  drawable.setBounds(mBounds);
  drawable.draw(mCanvas);

  Matrix expectedMatrix = new Matrix();
  expectedMatrix.setRotate(270, drawable.getBounds().centerX(), drawable.getBounds().centerY());
  expectedMatrix.postScale(1, -1);
  assertFalse(drawable.mRotationMatrix.isIdentity());
  AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
  verifySetBounds(expectedMatrix);
}
 
 类所在包
 同包方法