Android camera preview show only half bottom - android

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"/>

Related

Camera2 API preview aspect is broken

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.

Android surfaceview camera stretched

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.

Display two camera preview in same activity

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.

Cropping the Android camera

I'm developing an Android app that uses ZBar as a QR code library, and things are going sweet. Now, however, I'm building the interface for the app, and it requires that I show only a certain portion of the camera's feed at the bottom of the screen, something like this:
The camera view below should be full-sized, i.e. a cropped view and not a resized one. However setting the width and height of the FrameLayout has caused it to resize and squash the entire image into the tiny frame.
Is there a way to crop it? I know I could probably place an overlay over the original image, but how does one create a transparent square in the middle to display what I need?Besides, the QR reader would catch anything the camera captures, so if the user brought the QR code in front of the camera and it captured it "off screen" (by the part that's actually covered by the overlay), it would be extremely confusing.
So I guess what I'm saying is, I can't use an overlay to "crop" the picture. Is there any other way to do it?
As far my knowledge one cannot crop camera view but what you can do is re-size the frame and then capture the image.
Still i would suggest to refer this post
The first thought that comes to mind is to put your CameraPreview in a view inside a FrameLayout. Then add more views on top of the CameraPreview view to hide the parts that you do not want to be visible.
Or Perhaps just one view super-imposing the camera preview view with a PNG which covers everything with "cropped" area set as transparent.

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