I have an activity with action bar, SurfaceView (fullScreen, Behind the action bar) and a capture button at the bottom of the screen but on the surfaceView.
in the SurfaceViewChange I'm scanning all the supported Picture Sizes and chosing the Highest, but when I'm putting the same values in the Preview the outcome is stretched and if I take a picture it look ok, If I'm using the device screen height and width for the preview than its not stretched but at the result picture there are thing that were off frame.
All I want is an activity that takes picture with the highest resolution supported and preview it fine and play around with the captured picture.
The activity is in portrait!
any ideas?
The aspect ratio of the SurfaceView needs to match the aspect ratio of the camera preview. You can do this with a custom FrameLayout class.
For an example, see AspectFrameLayout in Grafika. You can see it used in the "Show + capture camera" and "Continuous capture" activities. Note how it's used in the layouts. Once you have it set up, you make one call with the camera preview parameters to set the desired aspect ratio, and the layout adjusts to match.
Related
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.
I used this library https://github.com/pedrovgs/DraggablePanel and I have a youtube fragment at top side, a camera preview (inside a fragment) at bottom side.
I want my camera preview show only half bottom part of camera (I don't take pictures, I just preview the bottom part of the front camera is like a mirror)
How do I crop my camera preview? Thank you all the help!
I've tried set SurfaceView height=screenwidth and parentView height=my_height but my top fragment (youtube fragment) was displayed like a SurfaceView
set fix height (e.g. 200dp)to surfaceView and align it to the bottom of the parent(screen).
and set the camera preview size accordingly
Camera.Parameters params = camera.getParameters();
params.setPreviewSize(your_width,your_height);
camera.setParameters(params);
You cannot crop the camera preview image in a SurfaceView.
You can hide the upper half of a SurfaceView by simply overlaying it with some other view (normal XML layout feature). But be careful: SurfaceView does not behave exactly as a "real" view, and it does not always "play by the rules" of view hierarchy. Typically you can overcome these glitches by building the view hierarchy programmatically in onResume().
An alternative is to switch to TextureView, or use a SurfaceTexture directly and display it in an OpenGL context of your choice. In the latter case, you can partially overlay the camera preview texture with some other OpenGL object, e.g. display decoded video stream in the same OpenGL context.
For me adding enabling hardwareAccelerated in Manifest solved the problem of preview of CameraX coming in half portion although I set match_parent as height width of PreviewView
<activity
android:name=".ui.CameraActivity"
android:label="#string/camera"
android:hardwareAccelerated="true"/>
Hello! Is there a good way of having a 16:9 SurfaceView, and then resize it bigger until it touches a screen edge? (so the SurfaceView is at its biggest size and still 16:9 and not outside the screen)
I have heard it is called letterbox, but havn't found any tutorial about it.
Thanks
There are two relevant sizes, the size of the Surface and the size of the View.
The size of the Surface is determined by the size of the video being rendered to it. You can't change this. A 720p video will set the size to 1280x720.
The size of the View is determined by the layout code. This can be set from within your app.
The system compositor (SurfaceFlinger) will scale the contents of the Surface so they fit in the View. To avoid distortion, you want to maintain the same aspect ratio. You do this with a custom FrameLayout.
For an example, see how AspectFrameLayout is used in Grafika's video players, e.g. this chunk of code.
I am trying to achieve a half screen camera preview similar to the one attached in the screen.
I tried nearly all camera preview examples, also tried my own but it either gets the SurfaceView resized to wrap preview sizes (so never half screen size) or it actually fits the half screen but the preview is stretched.
Is it possible to display two camera previews in same activity? We have two camera previews. One is placed top half of the activity window and other is placed in the bottom half of the activity window. Back camera preview is at the top and front camera preview is at the bottom.
Need to open only one camera at a time.
If it is possible how we can avoid the stretching of a specific sized camera preview? For eg. camera preview with size 200 x 200.