I use a GLSurfaceView to render camera preview output whilst simultaneously encoding it with the MediaCodec.
At some point, I want to resize the GLSurfaceView to show a larger camera preview. I do this by pausing the camera preview, applying new layout params to the GLSurfaceView and then restarting the camera preview.
The GLSurfaceView resizes successfully but the preview inside is the same size as before. The rest of the GLSurfaceView is filled with scrambled data (see attached image).
For anyone who find this, I never did manage to resolve my issue.
I had to tear down the whole view, camera and encoder and rebuild everything.
Related
I would like to handle the frame from YUV to RGB using the ScriptIntrinsecYUVtoRGB in the method ImageReader.OnImageAvailableListener().
It can be done? Until now I have done so:
I remaining with image white and the preview does not start anymore.
Suggestions?
You're not adding your TextureView surface to the capture session or the capture request anymore. Only the ImageReader Surface is being added to the outputSurfaces list and to captureRequestBuilder.addTarget().
So the camera is not drawing anything to the TextureView. Add it back in to both.
I want to achieve this kind of feature.
My initial camera preview:
Now I want to break this camera preview in two parts:
What I have tried:
Create a surface view to hold preview of camera.[Done]
Shift half of the surface view out off the screen[Done] now half of the surface view shift from out off the screen and only half is visible.
The problem is camera writes it's complete preview only on visible portion of surface view so the preview gets shrink in half of the screen.
Can anybody help me how can I achieve this?
Send the camera preview to a SurfaceTexture, then draw two rects with GLES, one with the left part of the preview, one with the right. Use a single SurfaceView for display.
You can find sample code in Grafika's "texture from Camera" Activity, which manipulates the camera output in various ways. Note in particular the "zoom" feature works by displaying a progressively smaller area of the preview while keeping the output rect the same size.
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).
I want to make an application that shows a camera preview on a surface view. the SurfaceView fills the screen, but I want to show the preview only on a certain position of the screen, in a smaller square. I want to draw other things later on the surfaceview too, around the preview. My problem is that the preview fills the whole surfaceview. Is there a way to resolve this problem? I read that I can't use more than one SurfaceView at the same time to separate the preview and the drawing.
Thank you for your help!