Droid 设备 - 不会旋转从相机捕获的图像? (相机.参数)

发布于 2024-08-15 15:40:38 字数 342 浏览 1 评论 0原文

我使用此相机代码要求相机旋转捕获的图像数据:

Camera.Parameters params = camera.getParameters();
params.set("rotation", 90);
camera.setParameters(params);

这似乎适用于除 Droid 之外的所有手机。还有其他人看过这个吗?图像数据始终是横向的,但是,Droid 上的本机相机应用程序可以生成纵向图像。

我想知道 Droid 是否只会遵循新的 Camera.Parameters.setRotation() 方法,但这似乎只在 API 级别 5 中可用?

I'm using this camera code to ask the camera to rotate the captured image data:

Camera.Parameters params = camera.getParameters();
params.set("rotation", 90);
camera.setParameters(params);

this seems to work on all phones, except the Droid. Has anyone else seen this? The image data is always landscape, however, the native camera app on the Droid produces portrait images ok.

I wonder if the Droid will only respect the new Camera.Parameters.setRotation() method, but this seems to only be available in API level 5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奈何桥上唱咆哮 2024-08-22 15:40:38

setRotation 在 Nexus One 上似乎也不适合我,但我确实通过遵循 Android 相机应用程序本身的示例来使图像旋转工作。
源代码可以在这里找到:
https://android.googlesource.com/platform/packages/apps/Camera

从 Camera.java 开始,但您还将查看 ImageManager.java、Util.java 和其他文件。

基本思想是,您监听方向变化并捕获拍摄照片时的方向。然后,当您在回调中获取图片字节时,您可以操作位图,对位图进行旋转。然后将旋转后的位图转换回 jpeg。完成后,您将不得不从相机应用程序中复制大量代码以进行此旋转。

setRotation also didn't seem to work for me on Nexus One, but I did get image rotation to work by following the example of the android Camera app itself.
The source code is available here:
https://android.googlesource.com/platform/packages/apps/Camera

Start with the Camera.java, but you'll also be looking at ImageManager.java, Util.java, and other files.

The basic idea is, you listen for orientation changes and capture what the orientation is at the time you snapped the picture. Then, when you get the picture bytes in the callback, you manipulate the bitmap, doing a rotation on the bitmap. Then convert the rotated bitmap back to jpeg. When you are done, you'll have had to copy a shocking amount of code from the camera app just for this rotation.

只有一腔孤勇 2024-08-22 15:40:38

旋转可能仅存储在 jpeg exif 标头中,如 setRotation 文档中所述。在 Droid 上确实是这样。您可以使用 jpeg 标头读取工具(例如 jhead)来验证这一点。您还可以使用 ExifInterface API 读取方向标签程序。

The rotation may just be stored in the jpeg exif header as explained in the setRotation document. On Droid that is actually the case. You can use jpeg header reading tools like jhead to verify this. You can also use the ExifInterface API to read the orientation tag in your program.

咋地 2024-08-22 15:40:38

Droid 运行 Android 2.0(好吧,现在是 2.0.1),分别是 API 级别 5 和 6。

因此,Droid 很可能只遵循(更明智的)2.0+ API 进行旋转。

但是,我猜您担心的是一系列设备类型和操作系统版本之间的兼容性,所以我想您在检测操作系统版本后必须通过反射调用 2.0+ API(使用 android.os.Build.VERSION_CODES< /代码>)。

The Droid runs Android 2.0 (well, now 2.0.1) which are API levels 5 and 6, respectively.

So it's quite possible that the Droid only respects the (more sensible) 2.0+ API for rotation.

However, I guess your concern is compatibility across a range of device types and OS versions, so I imagine you would have to invoke the 2.0+ API via reflection after detecting the OS version (using android.os.Build.VERSION_CODES).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文