某些设备(不在 EXIF 中)拍摄时 Android 相机无法解释的旋转 [英] Android camera unexplainable rotation on capture for some devices (not in EXIF)

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

问题描述

我正在做的事情似乎应该很简单,但是在阅读了我能找到的所有可能的 Stackoverflow 答案并在 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.

我正在使用预览 SurfaceView 并从我的 AndroidManifest.xml 中为 screenOrientation="landscape" 设置的活动中捕获图像.

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

我遵循示例相机应用程序代码并认为一切正常,直到我在几台运行 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.

Motorola Backflip (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.

这些摩托罗拉设备是怎么回事?我以为我的问题是摩托罗拉相机驱动程序没有旋转图像,所以找到了适用于 Android 的 Sanselan EXIF 阅读类,并准备自己旋转它们.有趣的是,有 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 和 NexusOne 的图像已旋转 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?

推荐答案

这实际上是一个特定于设备的问题,主要影响摩托罗拉设备.谷歌开发者包括一个 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
在顶级 ViewGroup 中覆盖 onDraw 并将画布旋转 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.

我还看到人们使用动画控制器来旋转视图.我无法克服的缺点是旋转后的视图不会拉伸以填满屏幕.请参阅 Georg 的回答了解示例实现.

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.

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

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