I'm using a TextureView to show the camera preview. For project needs it should be square and with rounded corners. This is working fine for the square part, as I can use the transformation Matrix to readjust the ratio deformation, but I have no clue on how to mask the video with rounded corners.
Basically what I've found is:
As the TextureView is showing the camera preview, I cant' lock the canvas to modify it.
I can't override onDraw as it's declared final in the TextureView class (it makes quite sense)
Is there any way to process the camera output out of the transformation Matrix?
Related
I have a fragment in which I'm using a TextureView, and I'm using the following link as a reference:
https://github.com/googlesamples/android-Camera2Basic
Is there a way to modify the scope of the camera to take a "landscape" (it's not really a landscape, just a different scope) picture, even though I'm on portrait mode?
I'm attaching a photo of what I'm trying to achieve. I have a round white frame, I want to the scope of the camera/TextureView to be in that frame, and I want to add a button that takes exactly what's in that frame (with rounded corners). Is that possible?
It is feasible.
You can use opengl to achieve it.
First, draw camera frame to a external gl texture, then draw the frame in the gl texture to the screen.
Crop the frame during the process of drawing to screen with modifying the texture coordinate and you will get your effect.
the way is here:
Crop video before encoding with MediaCodec for Grafika's "Continuous Capture" Activity
And the round corner effect can be also implement through modifying the texture coordinate. the way is here:
How to make TextureView play video with round corners and bubble effect
I want to display a camera preview in a circular shape using the camera2 api. I want to display the preview in a circular shape, but I dont't want the image to be captured in a circular shape.
The captured image would be a face( later want to implement face detection and auto capture). I did have a look at few questions already asked, but none of them are with the new camera2 api's and most of them talk about having an overlay image cropped with a transparent circle. But this will not work in a case where I need to auto detect a face(as the face may appear out side the cropped circular image).
Is there any way I can implement this ? I did try an example with TextureView and set it to a LinearLayout with fixed width and height, but the preview appeared a bit squeezed and in a square shape.
I don't see why face detection matters here - if you enable the camera API's face detector, it'll run on the full image no matter what you do in drawing it inside a circle.
You can either use a circle overlay on top of a correctly-shaped TextureView or SurfaceView, or do your own OpenGL rendering of a circle with the camera preview as a EGL texture.
The latter you'll probably want a GLSurfaceView for the OpenGL drawing context, and a SurfaceTexture to send camera data to and expose it as a EGL texture.
JPEGs captured will still be full-FOV, and the camera API will know nothing about your circular preview drawing, so face detection and everything else will work on the full field of view.
I have a camerapreview displayed on a textureView which works pretty well. But I can't mask the textureView with a circular mask. As soon as I use masking nothing gets displayed.
Is this not possible? Or is there another way?
You should use the API SurfaceTexture.
render camera frames to a SurfaceTexture created by yourself
draw the frame in the surfaceTexture to screen. During the drawing, you use a specific opengl vertex array to implement round corners.
Here is an very helpful article with source code on github.
https://medium.com/#fabrantes/rounded-video-corners-on-android-3467841cc1b
Can I set an ImageView to a camerapreview? Instead of using a surfaceview? I'm trying to make a camera preview semi transparent with setAlpha method, but It doesn't work on surfaceview. I mean it does work, but the camera preview is not semi transparent.
Well actually you can but not using SurfaceView. You achieve this by using GLSurface view, where you render each of your frame using shaders. In the fragment shader you can specify the opacity of your video. If you don't know OpenGL ES 2.0 you can start from here http://developer.android.com/training/graphics/opengl/index.html, but there are also many tutorial including rendering frames using opengl.
No you cannot do this, SurfaceView is the only way to create a Camera preview in Android.
I want to run android camera preview with a 640x480 resolution but display just 480x360. Right now I'm getting a stretched preview, even though I've tried to put the surface view in a frame layout or srollview. Can anyone tell me how this can be done?
A similar question has been asked before: How to crop camera preview?, but nobody answered.
Thanks
This can be achieved by using TextureView for camera preview. See https://developer.android.com/reference/android/view/TextureView.html.
Unlike SurfaceView, TextureView does not create a separate window but behaves as a regular View. This key difference allows a TextureView to be moved, transformed, animated, etc. For instance, you can make a TextureView semi-translucent by calling myView.setAlpha(0.5f).