【发布时间】:2017-06-27 06:30:08
【问题描述】:
我需要阅读Image 的一些Exif 属性(与Camera 一起获取或从Gallery 中选择)。
这是我如何启动Camera:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File file = new File(myObject.getLocalUrl());
Uri fileURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI);
startActivityForResult(intent, CAPTURE_IMAGE_REQUEST_CODE);
这是我如何启动Gallery Picker:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, getString(R.string.image_picker_select_image)), SELECT_IMAGE_FROM_GALLERY_REQUEST_CODE);
问题是,例如在第一种情况下(Camera),在Image被取出并保存在ExternalStorage中之后,Exif的信息就丢失了。
从Gallery 中挑选的Images 也是如此。这就是我在onActivityResult 方法中获得Image 的方式:
Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
最后是我如何读取Exif 数据:
ExifInterface exifInterface = null;
try {
exifInterface = new ExifInterface(myObject.getLocalUrl());
} catch (IOException e) {
e.printStackTrace();
}
String exifOrientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
String exifMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
String exifModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL);
我尝试了下一个:
- 使用我的设备
Camera(不使用我的App)拍摄picture。 - 使用
ExifInterface读取Exif数据。 - 它就像一个魅力。
所以我想问题是当Image 被保存(在它与Camera 一起使用之后)或从Gallery 中选择Image 时,Exif 数据会丢失。
我在Stackoverflow这里阅读了至少20-30个帖子,但基本上每个人都有的问题是orientationexif信息丢失,所以解决方案是在orientation中写正确的Exif 数据。
该解决方案对我来说并不好,因为我不想覆盖 Exif 数据,我只想阅读原始数据。
有什么想法/提示吗? 谢谢。
【问题讨论】:
-
new ExifInterface(myObject.getLocalUrl());。我的对象是什么?它与 onActivityResult() 有什么关系?更好地展示完整的代码。 -
That's how I get the Image in the onActivityResult method:。无关紧要。没关系。您应该向我们展示如何从 .jpg 文件中获取 exif。 -
the problem that everyone has is that the orientation exif information is lost, so the solution is writing the right orientation in the Exif data.。这一切对我来说毫无意义。 JPG 文件不会丢失 exif 信息。 -
in the first case (Camera), after the Image is taken and saved in the External Storage, the Exif information get lost.。 ?相机应用程序会将图像保存为 .jpg 文件。带有 exif 标头。就这样。你不是又存东西了吧?请显示完整的 onActivityResult 代码。 -
2. Read the Exif data using ExifInterface.。那么你有什么不同呢?从画廊或如何挑选?
标签: android image-processing camera exif photo-gallery