I wanted to create something like above, that three box, will be like a camera preview. Any idea or concept on what to do?
I tried getting instance of the camera and place it to three camerapreview objects, but i'm getting an error message, i guess, it's not allowed. here is my code:
private CameraPreview mPreview;
private CameraPreview mPreview2;
private CameraPreview mPreview3;
private FrameLayout preview;
private FrameLayout preview2;
private FrameLayout preview3;
mCamera=getCameraInstance();
mCamera2=getCameraInstance();
mCamera3=getCameraInstance();
mPreview=new CameraPreview(getApplicationContext(), mCamera);
mPreview2=new CameraPreview(getApplicationContext(), mCamera2);
mPreview3=new CameraPreview(getApplicationContext(), mCamera3);
preview=(FrameLayout)findViewById(R.id.camSetA_qr1);
preview.addView(mPreview);
preview2=(FrameLayout)findViewById(R.id.camSetA_qr1);
preview2.addView(mPreview2);
preview3=(FrameLayout)findViewById(R.id.camSetA_qr1);
preview3.addView(mPreview3);
and my getinstance code
public static Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open();
} catch (Exception e) {
}
return c;
}
No. Access to a camera is exclusive. See the Camera documentation, which says: If your application does not properly release the camera, all subsequent attempts to access the camera, including those by your own application, will fail and may cause your or other applications to be shut down.
PreviewView is a subclass of FrameLayout . To display the camera feed, it uses either a SurfaceView or TextureView , provides a preview surface to the camera when it's ready, tries to keep it valid as long as the camera is using it, and when released prematurely, provides a new surface if the camera is still in use.
The image is cropped to the aspect ratio of the camera preview, then scaled to fill the preview (field of view is reduced): On foldable devices, the orientation of the camera sensor can be portrait while the aspect ratio of the display is landscape: Figure 10.
A logical camera is then a grouping of two or more of those physical cameras. The output of the logical camera can be a stream that comes from one of the underlying physical cameras, or a fused stream coming from more than one underlying physical camera simultaneously.
You can only open a given camera (front or back) once; you cannot open the camera multiple times to produce multiple preview streams. In fact, on most devices, you can't open the front and back cameras simultaneously, since the camera processing pipeline is shared between the two cameras.
To do this, you need to only open the camera once, and then split the output preview data into the three parts that you then display.
If you need to run on Android versions before 3.0 (Honeycomb), then you need to use the preview callbacks. With them, you'll get a byte[] array of YUV data for each frame that you can then crop, convert to RGB, and place in an ImageView or SurfaceView.
On Android 3.0 or later, you can use the setPreviewTexture method to pipe the preview data into an OpenGL texture, which you can then render to multiple quads in a GLSurfaceView or equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With