读取图片回调的Andr​​oid JPEG EXIF​​元 [英] reading android jpeg EXIF metadata from picture callback

查看:215
本文介绍了读取图片回调的Andr​​oid JPEG EXIF​​元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我写一个相机应用的Messenger程序。我无法保存拍摄的图像以永久磁盘在任何时间。相机必须支持所有的方向。我的实现是熟悉的Surfaceview例子。我用的是Display类检测方向,并相应地旋转相机。在takePicture JPEG回调,我构建从byte []的一个位图,以解决一些我正在宽高比问题:的 Android摄像头API跨设备的噩梦

Background: I am writing a camera app for a messenger program. I cannot save the captured image to persistent disk at any time. The camera must support all orientations. My implementation is that of the familiar Surfaceview examples. I use the Display class to detect orientation and rotate the camera accordingly. In the takePicture jpeg callback, I construct a bitmap from the byte[] in order to get around some aspect ratio issues I was having: android camera API cross device nightmare

问题描述:在某些设备上,在ROTATION_270采取的构造位图(设备顺时针旋转90度)进来倒挂。到目前为止,这似乎是三星。我只能假设,也许相机被焊接到影响其他的方式什么的,但是这是不伦不类。虽然我可以检查一个位图是横着的,我不能在逻辑检查它是否是倒挂的尺寸,所以我需要访问的EXIF数据。

Problem Description: On some devices, the constructed Bitmap taken at ROTATION_270 (device rotated 90 degrees clockwise) comes in upside down. So far, it seems to be Samsung. I can only assume that maybe the camera is soldered on the other way or something to that affect but that's neither here nor there. While I can check if a Bitmap is sideways I can't logically check if it is upside down by dimensions so I need access to the EXIF data.

Android提供了一个解析器这个<一href="http://developer.android.com/reference/android/media/ExifInterface.html">http://developer.android.com/reference/android/media/ExifInterface.html但不幸的是它有它接受一个文件......我没有,不想一个构造函数。凭直觉我可以写一个构造函数的字节数组,但似乎真的很痛苦给予他们的电话为本地code <一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2.1_r1/android/media/ExifInterface.java">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2.1_r1/android/media/ExifInterface.java

Android provides a parser for this http://developer.android.com/reference/android/media/ExifInterface.html but unfortunately it has a single constructor which accepts a file... which I don't have and don't want. Intuitively I could write a constructor for a byte array but that seems really painful given their calls into native code http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2.1_r1/android/media/ExifInterface.java

我的问题,然后有两个部分:

My question then has two parts:

  1. 有谁知道,如果byte []数组包含完整的EXIF JPEG头 数据是或通过BitmapFactory.de code路径(...)/ BitmapFactory.com preSS(...)补充说,不知何故?

  1. Does anyone know if the byte[] array contains full EXIF jpeg header data as is or is the path through the BitmapFactory.decode(...) / BitmapFactory.compress(...) adding that somehow?

如果字节数组在此EXIF数据退出我怎么能解析出     以可靠的方式定向信息?

If this EXIF data exits in the byte array how can I parse out the orientation information in a dependable manner?

编辑12年10月18日

Edit 10/18/12

pcans的回答下面涉及到我的问题第2部分。正如我在下面他的回答评论指出,如果你想要使用的解析器,你就必须将信号源到您的项目。在链接,因此帖子中提到的改变已经取得了在这里转贴:<一href="https://github.com/strangecargo/metadata-extractor">https://github.com/strangecargo/metadata-extractor

pcans' answer below involves part 2 of my question. As I pointed to in the comments below his answer, if you want to use that parser you'll have to incorporate the source into your project. The changes mentioned in that linked SO post have already been made and reposted here: https://github.com/strangecargo/metadata-extractor

不过,对于第1部分,我得到0的标签从解析器回来时,我的字节数组,我从takePicture得到运行。我成为关注的字节数组没有我需要的数据。我会继续关注这一点,但欢迎任何进一步了解。

However, as to part 1, I'm getting 0 tags back from the parser when I run it with the byte array I get from takePicture. I'm becoming concerned that the byte array doesn't have the data I need. I will continue to look into this but welcome any further insight.

推荐答案

坏消息是:

Android的阿比可悲的是不会让你从,只能从文件读取EXIF数据。
ExifInterface 没有与构造的InputStream 。 所以,你必须自己分析JPEG的内容。

Android Api sadly won't allow you to read exif data from a Stream, only from a File.
ExifInterface don't have a constructor with an InputStream. So you must parse jpeg content by yourself.

好消息是:

API存在于纯Java这一点。你可以用这一个: http://www.drewnoakes.com/$c$c/exif/
它是开源的,并在Apache许可发布的2 下载,然后将其保存在您的/ libs文件夹中。
有一个构造函数的InputStream : <一href="http://www.drewnoakes.com/$c$c/exif/javadoc/com/drew/metadata/exif/ExifReader.html#ExifReader%28java.io.InputStream%29"><$c$c>public ExifReader(java.io.InputStream中的)
你可以建立一个的InputStream 字节[] 使用 ByteArrayInputStream的是这样的:

Api exists in pure java for this. You can use this one: http://www.drewnoakes.com/code/exif/
It's Open Source and published under Apache Licence 2. Download it and save it in your /libs folder.
There is a constructor with an InputStream: public ExifReader(java.io.InputStream is)
You can build an InputStream backed by your byte[] using a ByteArrayInputStream like this:

InputStream is = new ByteArrayInputStream(decodedBytes);

这篇关于读取图片回调的Andr​​oid JPEG EXIF​​元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆