Home Ask Login Register

Developers Planet

Your answer is one click away!

John Pod February 2016

Android Camera two preview from single camera

I want to build application android about camera two preview from a single camera enter image description here

I tried build app,I using SurfaceView in Android Studio but I have problem, enter image description here

I want example code, Can you help me please? Thank you so much.


I tried app.

AndroidSurfaceviewExample.java

package th.in.cybernoi.cardboardview;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


public class AndroidSurfaceviewExample extends Activity implements SurfaceHolder.Callback  {
    TextView testView;

    Camera camera;
    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;

    PictureCallback rawCallback;
    ShutterCallback shutterCallback;
    PictureCallback jpegCallback;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceStat        

Answers


rothloup February 2016

Each element in a layout needs to have a unique id. you have identified both screen elements as @+id/surfaceView. Try making them both unique. See modified layout file below - also don't forget to update your source code to populate both screen elements.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context="th.in.cybernoi.cardboardview.MainActivity">

    <SurfaceView
        android:id="@+id/surfaceViewLeft"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <SurfaceView
        android:id="@+id/surfaceViewRight"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

</LinearLayout>

Add code to your program to reference both SurfaceView objects. You just duplicate the code you already have. You should also check the rest of your program for other references to your SurfaceView object that need to be updated.

            surfaceViewLeft = (SurfaceView) findViewById(R.id.surfaceViewLeft);
        surfaceHolderLeft = surfaceViewLeft.getHolder();

        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        surfaceHolderLeft.addCallback(this);

        // deprecated setting, but required on Android versions prior to 3.0
        surfaceHolderLeft.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        surfaceViewRight = (SurfaceView) findVi 

Post Status

Asked in February 2016
Viewed 3,686 times
Voted 7
Answered 1 times

Search




Leave an answer


Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved

Search