【问题标题】:How to determine orientation of picture without ExifInterface?如何在没有 ExifInterface 的情况下确定图片的方向?
【发布时间】:2011-03-15 09:37:52
【问题描述】:

我将图像加载到bitmap 中,并且需要知道拍摄照片(来自相机)的方向才能正确显示。使用以下代码的方式很好(从 API 级别 5 开始),但是如果 android:minSdkVersion="4" 怎么办?还有其他方法吗?

ExifInterface exif = new ExifInterface(SourceFileName);     //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);

【问题讨论】:

标签: android orientation exif


【解决方案1】:
Matrix matrix = new Matrix();

ExifInterface exifReader = new ExifInterface(filePath);

int orientation = exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);

if (orientation ==ExifInterface.ORIENTATION_NORMAL) {

// Do nothing. The original image is fine.
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {

       matrix.postRotate(90);

} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {

       matrix.postRotate(180);

} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {

       matrix.postRotate(270);

}

【讨论】:

    【解决方案2】:

    轻松实现您自己的exif reader

    然后

    Metadata metadata = JpegMetadataReader.readMetadata(new File(imagePath));
    Directory jpegDirectory = metadata.getDirectory(JpegDirectory.class);
     int height = jpg.GetImageHeight();
     int width = jpg.GetImageWidth();
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2015-10-20
    相关资源
    最近更新 更多