How to use matrix camera preview left and right reverse on android?

老子叫甜甜 提交于 2019-12-25 07:50:10

问题


I want camera preview left and right reverse,

and I search for google, answer is use Matrix

is it right answer?

first, my source.

MainActivity.class

private Agen agen = null;
protected static Activity mainActivity = null;

@Override
protected void onCreate(final Bundle savedInstanceState) {

     agen = new Agen();
     agen.CameraSetting();
}
public static Activity getMainActivity() {
    return mainActivity;
}

Agen.class

private CamLiveView camLiveView;
private final FrameLayout liveFrame;
private final Context context;

public Agen() {
    Activity activity = MainActivity.getMainActivity();
    context = activity;

    liveFrame = (FrameLayout) activity.findViewById(R.id.liveview);
    public boolean CameraSetting() {
      boolean state = false;
      try {
          LiveCam livecam = CamManage.getInstance();

          camLiveView = new CamLiveView(context, livecam, this);
          if (liveFrame != null) 
              liveFrame.addView(camLiveView);
          state = true;
      } catch (Exception e) { 
          e.printStackTrace();
      } return state;
   }

CamManage.class

private static Camera mCamera = null;

public static LiveCam getInstance() {

    if (mCamera == null) {
        int cameras = Camera.getNumberOfCameras();

        mCamera = Camera.open(0);
        if (mCamera != null) {
            mCamera.lock();
        }
    } else {
    }
    return getLiveCam();
 }

getLiveCam

static private LiveCam getLiveCam() {
     LiveCam livecam = new LiveCam() ;

     Camera.Parameters params = mCamera.getParameters();
     liveCam.preSize = params.getPreviewSize();
     liveCam.preFormat = params.getPreviewFormat();
     liveCam.camera = mCamera;

     return liveCam;
}

LiveCam.class

public class LiveCam {
     public Camera camera;
     public Camera.Size preSize;
     public int preFormat;
}

this my source.

but I don't know where use matrix part.

in other words, I want camera preview left and right reverse.

please advice for me

thanks.

add

public class CamLiveView extends SurfaceView implements SurfaceHolder.Callback {

private SurfaceHolder mHolder;
private Camer mCamera;

private int preWidth;
private int preHeight;
private int preFormat;

private boolean playing = false;

public CamLiveView(Context context, LiveCam livecam) {
    super(context);

    mHolder = getHolder();
    mHolder.addCallback(this);

    mCamera = livecam.camera;

    preWidth = livecam.preSize.width;
    preHeight = livecam.preSize.height;
    preFormat = livecam.previewFormat;
  }

  @Override
  public void surfaceCreated(SurfaceHolder holder) {
     cameraPlay();
  }

  public boolean cameraPlay() {
      if (mHolder == null) 
         return false;

      try {
          mCamera.setPreviewDisplay(mHolder);
          mCamera.startPreview();
          playing = true;
      } catch (Exception e) {
         return false;
      } return true;
    }

来源:https://stackoverflow.com/questions/41117195/how-to-use-matrix-camera-preview-left-and-right-reverse-on-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!