Android SurfaceView or Camera2 API for camera preview - android

I am trying to implement the camera preview function into my app. After a lot of research I found that the best solution is the Camera2 API, but, it isn't supported on most phones. Is there a better solution to do this? For example, I read a lot about using a SurfaceView to load the camera preview on.

I simply followed the Android docs to use the camera API. Camera2 API is fairly new and I want to make sure all users can have it.

Related

Android Camera2 API : Capture video without preview

Main Question: How can I capture video without preview using Camera2 API?
I am trying to record video from a Background Service without showing any preview.
Here is the same question asked but I want to do it with Camera2 API.
I found a sample code in Camera2VideoJava and trying to use that in the service.
I am unable to understand what to do now because there is no documentation to do something like this.
Can anyone please help?
Just remove the preview View from the session creation, and from the repeating requests. Leave only the Surface from the MediaRecorder.
However, note that background services will not be able to use the camera starting in Android 9 Pie; you need at least a foreground service.
This seems to be the way to capture 4K video, but I haven’t tested it myself.
If you’re using the preview at 1080p, then the capture will be 1080p; that is my understanding.
You either have to capture without a preview surface at 4K, and / or use a GLSurfaceView at 4K resolutions.
The issue with GLSurfaceView at 4K is that it requires OpenGL ES 3.0, which many devices do not support.
There might be a way to pass the 4K buffer into a 1080p surface for preview, while also capturing 4K, but it’s not clear.
The main issue and the angst of most Camera2 API developers, is that OpenGL ES 3.0 doesn’t work on most devices, even if the camera itself supports 4K video.

Unable to create a surfaceview camera app that supports android 4.0 and above.

I'm planning to make a camera app that you can take a photo with a background image.
I guess there will be a need to use a Surfaceview? But the main problem is since the Camera is deprecated
there might be a need to use camera2 for android. I want to make a camera app in portrait mode but are there any
samples or tip? I googled but wasn't able to find a decent one. I would love to hear from you.
If you want to start with Camera2 API, this link will help you understand basics.
android-Camera2Basic(Github)
It is not necessary to use SurfaceView as you will see from code
that TextureView can also fulfill your requirement
The HdrViewfinder sample app uses SurfaceView with camera2, though it doesn't lock itself into portrait mode. But that's a relatively simple change.
Of course, camera2 was only added in Android 5.0, so if you need to support 4.0, you need to use the old camera API.

Can we use takePicture() in android without camera preview? I need to take a picture secretly for security purposes

I tried few codes from here :
How to capture an image in background without using the camera application
and this
Android Camera API Tutorial.
This question may seem duplicated, but I really want to know that can this be done over API level 21?
Thanks in advance.
According to android.developer.com, no.
https://developer.android.com/reference/android/hardware/Camera.html
"Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture."

How to make Live Camera Preview in Android

I've looked for tutorials on how to do this but everything I've found uses the deprecated Camera class. Can anybody point me to good resources on how I can show a live camera preview in my app? Or possibly show me some example code with the bare minimum needed to pull up a live preview of the camera?

Android Camera with Surfaceview

I want to built my own camera app in android including the following options pinch to zoom and autofocus without using camera intent. I already gone through some samples from Git hub but I couldn't make use of them.So, I decided to start learning Camera API from Google developers. Here I need a complete steps to develop my app and what to learn like camera, surface view and anything else.
Thanks in advance
I have done what you want to be done recently.
For android, there are 2 camera APIs
the camera api
and the camera2 api
camera api is deprecated on android api 21. starting from android api 21, you have to use camera2 api. so you have to learn both of them.
Camera api brother with SurfaceView.
Camera2 api brother with TextureView.
Camera2 api is quit alot different from Camera api, and also is much more complicated than Camera api.
You may want to take a look at my project SimpleCameraView, it is much clear than other projects. I just created this repository yesterday.
Things to Need to Learn to Build Custom Camera APP
Setting Camera,FlashLight and FILE_STORAGE Permissions in Manifest
SurfaceView and How to Use it.
Manual Control of Flash Light.
Lazy Loader for Displaying Images Taken without Memory Leaking.
And you can go through this for Sample : Build Custom Camera

Categories

Resources