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
Related
I am testing ExoPlayer2 using the google exoplayer-codelab-00 app https://github.com/googlecodelabs/exoplayer-intro . The goal is streaming from an IP camera. I have to rotate the camera video stream from landscape to portrait, shown on device in portrait mode.
I changed surface type to TextureView, in PlayerActivity.initializePlayer set playerView.setRotation(90). The video appears correctly rotated, but it is scaled at the initial size which would have been shown without the rotation, like this.
I tried changing width and height in playerView.getLayoutParams() + playerView.setLayoutParams(), but the video is never shown higher. Change of RESIZE_MODE_FIT to RESIZE_MODE_FILL just expands the video to fit the new width, but the height is not changed, like this.
Setting player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT) makes no difference either.
IMO some layer of the view stack does not get rotated with the playerView.setRotation(90) and the unrotated dimensions somehow constrain the rotated video. I want the rotation fixed, it is called before setting media item. The device will always be positioned in portrait mode (fixed installation). Thanks a lot for any hints, I am completely new to Android.
I am working on an App that captures the phone camera feed and display it into a GLSurfaceView and then in the renderer I add ImageViews to the screen in some specific coordinates.
The problem I am facing is that the camera feed in the GLSurfaceView is never full screen. In some Android versions it will put some black space horizontally in the top and bottom and in some other versions the black space will be smaller but vertical on the Left and Right of the screen.
I wanted to ask if there is any way to force fullscreen on every version ? I am fairly new to working with GLSurfaceView and nothing I tried works.
You could look into immersive mode to get rid of the system buttons if that's appropriate to your app: https://developer.android.com/training/system-ui/immersive
You should also look into the android.max_aspect manifest setting to eliminate black bars on very widescreen devices: https://android-developers.googleblog.com/2017/03/update-your-app-to-take-advantage-of.html
You should also look into supporting display cutouts (notches): https://developer.android.com/guide/topics/display-cutout/
As mentioned in the comments by BDL, if the screen and camera aspect ratio don't match, then you are going to have to have black bars, or cut off some content.
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.
I am using the Camera2 API to setup an imagecapture fragment. I only want to use the camera in portrait mode. So i have set this line in the manifest in the fragment's parent activity:
android:screenOrientation="portrait"
Which locks the camera preview to portrait. However, the image aspect is just wrong. When the image is captured, there is no issues with the aspect, and the image looks as it should, but is still not in full screen. I suspect the camera output is stretched to fill the screen in my preview. How do i make both the preview and the captured image fill the entire screen and keep its aspect ratio like Snapchat does it?
I have been using the Google sample as my reference, and changed the AutoFitTextureView to match_parent in the XML layout file.
this is how it looks in normal portrait
and this is how it looks when i rotate the phone and is still in portrait mode
AutoFillTextureView attempts to keep the aspect ratio correct, but if you're changing its layout parameters, it may not be able to.
Do things work correctly if you don't make it 'match_parent'?
In general, Android UI elements will fill themselves with the input data, so you need to set the View's size to the right aspect ratio to avoid stretching.
For anyone who has been facing this issue like I was and if you have been using the google sample from before Jun 2017, then tweaking a line in your AutoFitTextureView should fix the preview's aspect ratio. It's as simple as changing "<" to ">" which you can see here.
is there a way to have a small camera preview inside a view? Not the classic fullscreen preview, I mean.
My idea is to create an app that allows the user to take pics of himself with the frontal camera, when it's dark.
Basically, I thought to put a small preview of the camera on the corner of the screen and setting the remaining part to full brightness (to use it like a "self flash").
Well, I don't have problems actually to set a view to a full brightness value, but I don't have any idea how to resize the frontal camera preview.
I hope you understood my intention...
Any help would appreciated!
I don't believe this idea will hold water, because the brightness of the screen may not be enough. But the technical question you ask is not very hard: you can put the ViewSurface for your preview in the main activity's xml with any size you choose (you can use the usual WISIWYG layout editor in ADS or AndroidStudio).