如何确定照片的方向,而不会ExifInterface?方向、照片、ExifInterface

2023-09-04 23:31:41 作者:じ执笔、画倾城

我将图像加载到一个位图,并需要知道抽放图片(从摄像机)的方向正确地表现出来。使用下面的code的方式工作很好(因为API等级5),但是做什么,如果安卓的minSdkVersion =4?有另一种方式?

I load an image into a bitmap and need to know the orientation of taked picture (from camera) to show it correctly. The way to use the following code is working nice (since API Level 5), but what to do if android:minSdkVersion="4"? Is there another way?

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

在此先感谢!

Thanks in advance!

推荐答案

轻松实现自己的exif读者

然后

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