对于某些设备上捕获Android摄像头无法解释的旋转(而不是在EXIF) [英] Android camera unexplainable rotation on capture for some devices (not in EXIF)

查看:154
本文介绍了对于某些设备上捕获Android摄像头无法解释的旋转(而不是在EXIF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么,似乎像它应该是简单的,但我还是输了我读过的每一个可能的答案#1我能找到和Google搜索的每一篇文章我能找到后。

What I'm doing seems like it should be simple, but I'm still lost after I've read every possible Stackoverflow answer I can find and Googled every article I can find.

我使用的是preVIEW SurfaceView,并从被设置为我的Andr​​oidManifest.xml screenOrientation =景观活动拍摄的图像。

I'm using a preview SurfaceView and capturing an image from an activity that is set for screenOrientation="landscape" in my AndroidManifest.xml.

我跟着样品相机应用code,以为事情工作,直到我想我上运行1.5的一些摩托罗拉设备的应用程序。

I followed the sample Camera app code and thought things were working until I tried my app on a few Motorola devices running 1.5.

我在运行正常的OrientationEventListener,我使用反射来看看设置旋转这样:

I have the OrientationEventListener running OK and I use reflection to see if set the rotation as such:

final int latchedOrientation = roundOrientation(mLastOrientation + 90);

Parameters parameters = preview.camera.getParameters();

JPLog.d("Setting camera rotation = %d", latchedOrientation);
try {
    // if >= 2.0
    Method method = Camera.Parameters.class.getMethod("setRotation",
        int.class);

    if(method != null) {
        method.invoke(parameters, latchedOrientation);
    }

} catch(Throwable t) {
    // if < 2.0
    parameters.set("rotation", latchedOrientation);
}

preview.camera.setParameters(parameters);

歌NexusOne(OS 2.2) - 的伟大工程。 latchedOrientation = 0,画面不正常的EXIF头的任何转动。

NexusOne (OS 2.2) - Works great. latchedOrientation = 0, picture OK without any rotation in the EXIF header.

的T-Mobile G1(OS 1.6) - 同样的伟大工程。 latchedOrientation = 0,图片确定。

T-Mobile G1 (OS 1.6) - Also works great. latchedOrientation = 0, picture OK.

摩托罗拉后空翻(OS 1.5) - 图像旋转。 latchedOrientation = 0,画面没有EXIF旋转它。

Motorola Backflip (OS 1.5) - Image rotated. latchedOrientation = 0, picture has no EXIF rotation in it.

摩托罗拉CLIQ(OS 1.5) - 图像旋转。 latchedOrientation = 0,画面没有EXIF旋转它。

Motorola CLIQ (OS 1.5) - Image rotated. latchedOrientation = 0, picture has no EXIF rotation in it.

这是怎么回事这些摩托罗拉设备?我想我的问题是,摩托罗拉的摄像头驱动是不旋转的图像,因此找到了Sanselan EXIF​​阅读课Android和是preparing旋转他们自己。有趣的是,有EXIF头,但没有旋转的元素。

What's going on with these Motorola devices? I thought my problem was the Motorola camera driver wasn't rotating the images, so found the Sanselan EXIF reading classes for Android and was preparing to rotate them myself. Funny thing is, there is EXIF headers but no rotation element.

如果我手动设置旋转90度,图像出来完美的摩托罗拉设备,但现在的G1和Nexus One的有(不是我想要的)被旋转90度的图像。必须有一些东西我没有得到这里。

If I set the rotation manually to 90 degrees, the images come out perfect the Motorola devices, but now the G1 and the NexusOne have images that are rotated 90 degrees (not what I want). There has to be something I'm not getting here.

我怀疑这是一个1.5的问题,或者它在其他有人会已经发布的信息?

I'm doubting this is a 1.5 issue, or else someone would've posted info on it?

推荐答案

这实际上是主要影响摩托罗拉设备的设备特定问题。在谷歌开发者包括 <一个href="http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29">setDisplayOrientation在API调用8来解决此问题。主要缺陷提交这里

This is actually a device-specific issue that mostly affects Motorola devices. The google devs included a setDisplayOrientation call in API 8 to work around the issue. The main bug is filed here.

对于那些不能去API 8,两种常见的解决方案是:

For those that can't go to API 8, the two common solutions are:

覆盖的OnDraw
覆盖的OnDraw在顶层的ViewGroup和旋转画布90度以补偿该旋转。注意:有一个警告这里的触摸事件还需要旋转。

Override onDraw
Override onDraw in a top-level ViewGroup and rotate the canvas by 90 degrees to compensate for the rotation. Note there is a caveat here as your touch events will also need to be rotated.

使用风景模式
锁定活动为横向模式,但得出的资产,如果他们是在肖像。这意味着你做你的布局和旋转图像资产看起来你是在纵向模式下,这样的观点看起来正常。这不幸使得很难使用菜单,因为菜单打开水平

Use Landscape Mode
Lock the activity to landscape mode but draw assets as if they are in portrait. This means you do your layout and rotate your image assets to look like you are in portrait mode so that the view looks normal. This unfortunately makes it difficult to use the menu since the menu will open horizontally.

我也看到有人使用动画控制器来旋转视图。这里的缺点,我是不是能够克服的是,旋转视图不拉伸以填充屏幕。请参阅<一href="http://stackoverflow.com/questions/3444764/rotate-view-hierarchy-90-degrees/4624242#4624242">answer由乔治·的一个样本实现。

I have also seen people use an animation controller to rotate the view. The drawback here that I wasn't able to overcome is that the rotated view doesn't stretch to fill the screen. See the answer by Georg for a sample implementation.

这篇关于对于某些设备上捕获Android摄像头无法解释的旋转(而不是在EXIF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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