Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Camera2 API Equivalent of setDisplayOrientation()?

With android.hardware.Camera, in order to have the camera output appropriately track the device movement, we need to hook up an OrientationEventListener to the setDisplayOrientation() method on Camera. That way, as the user twists the device around, we can keep what is "up" on the camera preview in sync with what is "up" in the real world. This is particularly true for rotating the device around the Y axis (i.e., flipping from landscape to reverse-landscape or back).

For most orientation changes, the android.hardware.camera2 API seems to "just work". However, for that Y-axis rotation (landscape -> reverse-landscape or vice versa), the camera preview winds up being inverted.

What is the equivalent of calling setDisplayOrientation() on Camera for the Camera2 API, so we can handle this scenario?

like image 424
CommonsWare Avatar asked Nov 02 '15 13:11

CommonsWare


People also ask

What is the use of Camera2 API?

Camera2 is the low-level Android camera package that replaces the deprecated Camera class. Camera2 provides in-depth controls for complex use cases, but requires you to manage device-specific configurations. For more information, see the Camera2 reference documentation.

How do I install camera 2 API?

prop in the /system partition of your Android device, you can enable the Camera2 API functionality. First you'll need a rooted phone, and a method of editing your build. prop file. You can either use a root file explorer app (like ES Explorer) to navigate to the /system partition on your phone and open build.

What is camera API?

android. hardware. camera2. This package is the primary API for controlling device cameras. It can be used to take pictures or videos when you are building a camera application.


1 Answers

As you've noticed, this is supposed to "just work" for SurfaceView on the camera2 API.

As such, there's no equivalent of setDisplayOrientation().

We haven't heard of this issue before now, so a few questions:

  1. Do you have your app locked to landscape, or are you allowing orientation changes?
  2. Do you handle your own orientation changes, or are you having the framework tear down and restart your app when orientation changes?
  3. Do you trigger any sort of re-layout when the 180-degree rotation occurs, for example to adjust where the shutter button is?
like image 200
Eddy Talvala Avatar answered Sep 24 '22 02:09

Eddy Talvala