Change camera preview mode on changing screen orientation - android

I am writing an application where I have to show a video and a camera preview mode in same screen. The requirement is when the screen orientation change to landscape the video and cameraPreview should show side by side and when orientation change to portrait then the video and cameraPreview should be bottom-up.
I am not sure how to achieve this. Can someone tell me is there any library available or if not how to achieve this.

use the ionic native screen-orientation plugin and detect the orientation and change width and height according to that.

Related

Camera2 API -> on Orientation Change(from portrait to landscape), captured image is larger than camera preview

For my project requirement, I am using Google's camera2 api basic example and I don't want to restart my activity on orientation change. But, while doing this I face an issue that If i change my view from portrait to landscape mode camera preview is not redrawn and aspects of portrait are applied in landscape mode. Due to this when i capture image, Camera captures larger image then what is shown on preview in landscape mode.
Reproduction steps :
Pre condition :
Handle onOrientationChange in manifest file for the activity.
Steps:
1. Open camera in portrait mode and then rotate to landscape mode
2. Capture image
For this, I called closeCamera() and then openCamera() in onConfigurationChanged() but it is not a good solution beacuse it takes a lot of time to recreate everything. Is there any way I can redraw the preview surface ?

Achieve react native app layout for landscape and portrait

I am creating the react native app and quite new about this. In this app, I am creating image slider, I want that image slider adjust it's view on both portrait and landscape automatically.
This Orientation plugin checks either the device is in landscape or in portrait view.
Shall I need to write layout/view for landscape and portrait independently?
Or is there any way that I can follow for my requirement.
React native uses flexbox for layout rendering. Using flexbox UI will be same for both landscape and portrait mode.

How to force change layouts in Android

I have my app's orientation forced via
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
but when I want to change layout to landscape one (when device is rotated - i get the info via OrientationEventListener) it just doesnt render it as landscape. Is there any way how to force it? Just like imagine holding your device in portait mode but the layout is landscape. but not achieved via
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
android:screenOrientation="landscape" in manifest
I want to have it forced to portait because I'm building a camera app and it messes up the camera everytime and I want to have it like the default camera has it - no change, just the button orientation. If that makes sense.
A lot of camera apps achieve this by rotating Views and it's a good way to do it because you don't have to deal with Activity lifecycle as well as camera lifecycle. They have a locked orientation but they use accelerometer to get device rotation and then rotate Views accordingly.
Camera API gives you ability to set camera rotation as well as picture orientation. Picture orientation should be set to zero because Camera API is unreliable with this.
Use accelerometer to determine real device rotation and set EXIF rotation of the picture to a correct one.

Fastest way to update the activity for all the orientations

In my android Activity I need to update the camera preview orientation and the UI according to the device Orientation. And I need all orientations for my activity namelyPortrait,Landscape,Landscape reverseandportrait reverse`.
I use the Android API demo for the camera preview. I found that when I use fullSensor for orientation setting in my AndroidManifest.xml and call the setCameraDisplayOrientation() on surfaceChanged() method of the Preview class(I am referring to the CameraPreview.java in the API demo sources) I get the desired behavior.
But there is a big delay on each orientation switch. When I set the orientation to Landscape in the manifest the preview is smooth but the UI is not updating according to the device orientation. I need the orientation to be set to Landscape and the UI to change according to all the four orientations namely Portrait up, Landscape right, Landscape left and Portrait down. What is the optimal way of achieving the same with good performance?

Camera Preview code gives as upside down image view android

I am Using a onCLick over a button to capture an image but when we see the preview it is upside down in vertical mode where as when the same preview is seen through horizontal preview renders correctly.
Please let me know what tweaks are necessary to readjust the preview.
You have to take into account, that camera preview image origin is on top right corner if in portait mode, and axes are swapped - and it does not depend on phone orientation. You will have to flip image to display it in portrait mode properly.
take a look at
android.hardware.Camera.setDisplayOrientation
http://developer.android.com/reference/android/hardware/Camera.Parameters.html
and
android.hardware.Camera.Parameters.setRotation
http://developer.android.com/reference/android/hardware/Camera.html

Categories

Resources