Bootstrap

相机demo的java部分

自己开发的相机APP代码java部分

CameraActivity.java



package com.example.android.camera2basic;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class CameraActivity extends AppCompatActivity {
   

      private Button btn1,btn2,btn3,btn4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);


        btn1 = (Button) findViewById(R.id.button1);
        btn2 = (Button) findViewById(R.id.button2);
       /* btn3 = (Button) findViewById(R.id.button3);
        btn4 = (Button) findViewById(R.id.button4);*/
        checkPermission();
        btn1.setOnClickListener(new View.OnClickListener() {
   
            @Override
            public void onClick(View v) {
   
               // if (null == savedInstanceState) {
   
                    getSupportFragmentManager().beginTransaction()
                            .replace(R.id.container, Camera2BasicFragment.newInstance())
                            .commit();
               // }
            }
        });
          btn2.setOnClickListener(new View.OnClickListener() {
   
              @Override
              public void onClick(View v) {
   
                  getSupportFragmentManager().beginTransaction()
                          .replace(R.id.container, CameraFragment.intent())
                          .commit();
              }
          });
        //分辨率切换
     /*   btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container, Camera2BasicFragment2.newInstance())
                        .commit();
            }
        });


        //录像功能
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                      getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container, Camera2VideoFragment.newInstance())
                        .commit();
            }
        });*/


    }
              //读取相册的图片权限设置
    private void checkPermission() {
   
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
   
            String[] permissions = new String[]{
   Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
            for (String permission : permissions) {
   
                if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
   
                    ActivityCompat.requestPermissions(this, permissions, 200);
                    return;
                }
            }
        }
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[]
            grantResults) {
   
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && requestCode == 200) {
   
            for (int i = 0; i < permissions.length; i++) {
   
                if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
   
                    Toast.makeText(this, "请在设置中打开摄像头和存储权限", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", getPackageName(), null);
                    intent.setData(uri);
                    startActivityForResult(intent, 200);
                    return;
                }
            }
        }
    }

}

Camera2BasicFragment.java

/*
 * Copyright 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.camera2basic;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.Image;
import android.media.ImageReader;
import android.media.MediaRecorder;
import android.media.ThumbnailUtils;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.util.Range;
import android.util.Size;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;




/* 拍照预览流程图
   UI控件分辨率:protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   预览分辨率:texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
    图片分辨率:mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),ImageFormat.JPEG, 2);

TextureView设置预览方向:mTextureView.setTransform(matrix); 其他预览控件,不是这个方法。
图片方向:captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

屏幕旋转:private void configureTransform(int viewWidth, int viewHeight)

1-> public void onViewCreated(final View view, Bundle savedInstanceState) {
  2-> mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture);//获取mTextureView 
1-> public void onResume() {
  2-> startBackgroundThread();	//为相机开启了一个后台线程,这个进程用于后台执行保存图片等相关的工作
    3-> mBackgroundThread = new HandlerThread("bruceCameraBackground");
    3-> mBackgroundThread.start();
    3-> mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
  2-> if (mTextureView.isAvailable()) {openCamera(mTextureView.getWidth(), mTextureView.getHeight());	//mTextureView已经创建,SurfaceTexture已经有效,则直接openCamera,用于屏幕熄灭等情况,这时onSurfaceTextureAvailable不会回调。
  2-> else {mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);		//SurfaceTexture处于无效状态中,则通过SurfaceTextureListener确保surface准备好。
	3-> public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
      4-> openCamera(width, height);		//SurfaceTexture有效即可openCamera
        5-> requestCameraPermission();//请求权限
        5-> setUpCameraOutputs(width, height);//包括对相机设备的选择,ImageReader的初始化和参数、回调设置。设置显示的转化矩阵,即将预览的图片调整至显示图层的大小。
          6-> for (String cameraId : manager.getCameraIdList()) {//获取摄像头可用列表
          6-> CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);获取相机的特性
          6-> Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);// 不使用前置摄像头
          6-> mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),ImageFormat.JPEG, 2);//设置ImageReader接收的图片格式,以及允许接收的最大图片数目
          6-> mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);//设置图片存储的监听,但在创建会话,调用capture后才能有数据
            7-> public void onImageAvailable(ImageReader reader) {//图片有效回调
              8-> reader.acquireNextImage()//获取图片image
              8-> mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));///通知ImageSaver线程保存图片
                9-> private static class ImageSaver implements Runnable {//保存图片线程 
                  10-> public void run() {
                    11-> output = new FileOutputStream(mFile);output.write(bytes);//保存图片到文件
          6-> int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();//获取显示方向
          6-> mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);//获取sensor方向
          6-> mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),//获取最优的预览分辨率
          6-> mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());//设置TextureView预览分辨率
          6-> mCameraId = cameraId;//获取当前ID
        5-> configureTransform(width, height);//配置transformation,主要是矩阵旋转相关
        5-> CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
        5-> manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);//打开相机---------------------
          6-> private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {//打开相机设备状态回调---------------------
            7-> public void onError(@NonNull CameraDevice cameraDevice, int error) {//打开错误  
            7-> public void onDisconnected(@NonNull CameraDevice cameraDevice) {//断开相机
            7-> public void onOpened(@NonNull CameraDevice cameraDevice) {//打开成功
              8-> mCameraDevice = cameraDevice;//从onOpened参数获取mCameraDevice
              8-> createCameraPreviewSession();//创建会话
                9-> SurfaceTexture texture = mTextureView.getSurfaceTexture();//获取SurfaceTexture
                9-> texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());//设置TextureView大小 
                9-> Surface surface = new Surface(texture);//创建Surface来预览
                9-> mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);//创建TEMPLATE_PREVIEW预览CaptureRequest.Builder
                9-> mPreviewRequestBuilder.addTarget(surface);//CaptureRequest.Builder中添加Surface
                9-> mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),new CameraCaptureSession.StateCallback() {//创建会话---------------------
                  10-> public void onConfigureFailed(//创建会话失败
                  10-> public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {//创建会话成功
                    11-> mCaptureSession = cameraCaptureSession;//从onConfigured参数获取mCaptureSession
                    11-> mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);//设置AF自动对焦模式
                    11-> mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);//设置AE模式
                    11-> mPreviewRequest = mPreviewRequestBuilder.build();//转换为CaptureRequest
                    11-> mCaptureSession.setRepeatingRequest(mPreviewRequest,mCaptureCallback, mBackgroundHandler);//设置预览,和拍照是同一个回调mCaptureCallback---------------------
                      12-> private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {//预览回调---------------------
                        13-> public void onCaptureProgressed(@NonNull CameraCaptureSession session,@NonNull CaptureRequest request,@NonNull CaptureResult partialResult) {//预览过程中
                        13-> public void onCaptureCompleted(@NonNull CameraCaptureSession session,@NonNull CaptureRequest request,@NonNull TotalCaptureResult result) {//预览完成,和拍照是同一个回调mCaptureCallback
                          14-> process(result); //从onCaptureCompleted参数获取CaptureResult
                            15-> case STATE_PREVIEW: {//预览状态,则什么都不做
                            15-> case STATE_WAITING_LOCK: {//等待焦点被锁时,由设置拍照流时设置的STATE_WAITING_LOCK
                              16->captureStillPicture();//进行拍照
                                17-> final CaptureRequest.Builder captureBuilder =  mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);//设置TEMPLATE_STILL_CAPTURE拍照CaptureRequest.Builder
                                17-> captureBuilder.addTarget(mImageReader.getSurface());//添加拍照mImageReader为Surface
                                17-> captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);//设置AF
                                17-> captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));//设置图片方向
                                17-> mCaptureSession.stopRepeating();//停止预览 
                                17-> mCaptureSession.abortCaptures();//中断Capture
                                17-> mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);//重新Capture进行拍照,这时mImageReader的回调会执行并保存图片---------------------
                                  18-> CameraCaptureSession.CaptureCallback CaptureCallback  = new CameraCaptureSession.CaptureCallback() { //拍照流程执行完成回调---------------------
                                    19-> public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                      20-> showToast("Saved: " + mFile);//提示拍照图片已经保存
                                      20-> unlockFocus();//释放焦点锁,重新开启预览。
                                        21-> mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);//重新设置AE/AF
                                        21-> mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,mBackgroundHandler);//重新设置AE/AF,通过mPreviewRequestBuilder.build()只发送一次请求,而不是mPreviewRequest。
                                        21-> mState = STATE_PREVIEW;//设置预览状态,通知mCaptureCallback回到预览状态
                                        21-> mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,mBackgroundHandler);//重新进入预览,使用mPreviewRequest
3-> public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { 
      4-> configureTransform(width, height);
3-> public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
    3-> public void onSurfaceTextureUpdated(SurfaceTexture texture) { 
      4-> //镜像模式获取bitmap
1-> public void onClick(View view) {
  2-> takePicture();//拍照
    3-> lockFocus() {//拍照过程中锁住焦点
      4-> mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); //通知camera锁住对焦
      4-> mState = STATE_WAITING_LOCK;//设置状态,通知mCaptureCallback等待锁定
      4-> mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,mBackgroundHandler);//通知camera锁住对焦和状态只发送一次请求,是同一个回调mCaptureCallback,只是等待焦点被锁,切换为STATE_WAITING_LOCK再真正进行拍照---------------------

*/
public class Camera2BasicFragment extends Fragment
        implements View.OnClickListener, ActivityCompat.OnRequestPermissionsResultCallback, Chronometer.OnChronometerTickListener {
   

    /**
     * Conversion from screen rotation to JPEG orientation.
     */
    private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
    private static final int REQUEST_CAMERA_PERMISSION = 1;
    private static final int REQUEST_VIDEO_PERMISSIONS = 1;
    private static final String FRAGMENT_DIALOG = "dialog";
    private Button mButtonVideo;
    private Button mButtonPz;//拍照
    private TextView mButtonFz;//翻转
    private TextView mButtonFbl;//分辨率
    private TextView mButtonSy;//水印
    private TextView mButtonLx;//录像
    private TextView mButtonCkx;//参考线
    private TextView mButtonMdz;//慢动作
    private Chronometer mchronometer;//录制时长显示
    private TextView mBntTime;//延迟拍照
    private TextView mButtonYc;//延迟
    private int yc_flag=0;//延迟flag
    private static TextView mButtonSgd;//闪光灯
    private static int sgd_flag=0;
    private static TableLayout tableLine;
    private static int line_flag=0;//参考线
    private static ImageView mimage_thumbnail;//缩略图


    private static Bitmap bitMap;
    private static Handler handler = new Handler() {
   
        @Override
        public void handleMessage(Message msg) {
   
            if (msg.what == 1) {
   
                mimage_thumbnail.setImageBitmap(bitMap);
            }else if (msg.what==2){
   
                if(line_flag==0){
   
                    line_flag=1;

                    tableLine.setVisibility(View.VISIBLE);//参考线显示状态
                }else {
   
                    line_flag=0;
                    tableLine.setVisibility(View.GONE);//隐藏状态,且不占空间
                }

            }else if(msg.what==3){
   
                if(sgd_flag==0){
   
                    sgd_flag=1;
                    mButtonSgd.setText("闪关灯: 开");
                }else {
   
                    sgd_flag=0;
                    mButtonSgd.setText("闪关灯: 关");
                }
            }
        }
    };

    static {
   
        ORIENTATIONS.append(Surface.ROTATION_0, 90);
        ORIENTATIONS.append(Surface.ROTATION_90, 0);
        ORIENTATIONS.append(Surface.ROTATION_180, 270);
        ORIENTATIONS.append(Surface.ROTATION_270, 180);
    }

    private static final int SENSOR_ORIENTATION_DEFAULT_DEGREES = 90;
    private static final int SENSOR_ORIENTATION_INVERSE_DEGREES = 270;
    private static final SparseIntArray DEFAULT_ORIENTATIONS = new SparseIntArray();
    private static final SparseIntArray INVERSE_ORIENTATIONS = new SparseIntArray();
    static {
   
        DEFAULT_ORIENTATIONS.append(Surface.ROTATION_0, 90);
        DEFAULT_ORIENTATIONS.append(Surface.ROTATION_90, 0);
        DEFAULT_ORIENTATIONS.append(Surface.ROTATION_180, 270);
        DEFAULT_ORIENTATIONS.append(Surface.ROTATION_270, 180);
    }

    static {
   
        INVERSE_ORIENTATIONS.append(Surface.ROTATION_0, 270);
        INVERSE_ORIENTATIONS.append(Surface.ROTATION_90, 180);
        INVERSE_ORIENTATIONS.append(Surface.ROTATION_180, 90);
        INVERSE_ORIENTATIONS.append(Surface.ROTATION_270, 0);
    }

    private static final String[] VIDEO_PERMISSIONS = {
   
            Manifest.permission.CAMERA,
            Manifest.permission.RECORD_AUDIO,
    };

    /**
     * Tag for the {@link Log}.
     */
    private static final String TAG = "Fragment_TextureView";

    /**
     * Camera state: Showing camera preview.
     */
    private static final int STATE_PREVIEW = 0;//预览状态

    /**
     * Camera state: Waiting for the focus to be locked.等待自动对焦的焦点被锁状态
     */
    private static final int STATE_WAITING_LOCK = 1;

    /**
     * Camera state: Waiting for the exposure to be precapture state.等待曝光为预捕获状态
     */
    private static final int STATE_WAITING_PRECAPTURE = 2;

    /**
     * Camera state: Waiting for the exposure state to be something other than precapture.等待曝光不是预捕获状态
     */
    private static final int STATE_WAITING_NON_PRECAPTURE = 3;

    /**
     * Camera state: Picture was taken.	拍照状态,APP开始获取图片数据流进行保存
     */
    private static final int STATE_PICTURE_TAKEN = 4;

    /**
     * Max preview width that is guaranteed by Camera2 API
     */
    private static final int MAX_PREVIEW_WIDTH = 1920;

    /**
     * Max preview height that is guaranteed by Camera2 API
     */
    private static final int MAX_PREVIEW_HEIGHT = 1080;

    /**
     * {@link TextureView.SurfaceTextureListener} handles several lifecycle events on a
     * {@link TextureView}.
     */
    private final TextureView.SurfaceTextureListener mSurfaceTextureListener
            = new TextureView.SurfaceTextureListener() {
   //TextureView回调

        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
   
            openCamera(width, height);//SurfaceTexture有效即可openCamera
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
   
            configureTransform(width, height);// 当屏幕旋转时,预览方向改变时, 执行转换操作. 默认情况下TextureView通过此方法设置预览方向
        }

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
   
            return true;
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture texture) {
   //可获取bitmap
        }

    };

    /**
     * ID of the current {@link CameraDevice}.正在使用的相机id
     */
    private String mCameraId;
    private int flag_Fz=0;
    private int flag=0;
    private int flag_Lx = 0;//录像
    private  int text_flag=0;//水印
    private int video_flag1=0;//慢动作

    private int width_T=3968;
    private int height_T=2976;
    private boolean mIsRecordingVideo;
    private int camera_flag=0;
    /**
     * An {@link AutoFitTextureView} for camera preview.预览使用的自定义TextureView控件
     */
    private AutoFitTextureView mTextureView;
    private TextView text1;


    /**
     * A {@link CameraCaptureSession } for camera preview.预览用的获取会话
     */
    private CameraCaptureSession mCaptureSession;

    /**
     * A reference to the opened {@link CameraDevice}.正在使用的相机
     */
    private CameraDevice mCameraDevice;

    /**
     * The {@link Size} of camera preview.预览数据的尺寸
     */
    private Size mPreviewSize;

    /**
     * {@link CameraDevice.StateCallback} is called when {@link CameraDevice} changes its state.相机状态改变的回调函数
     */
    private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
   //打开相机设备状态回调

        @Override
        public void onOpened(@NonNull CameraDevice cameraDevice) {
   //打开成功
            // This method is called when the camera is opened.  We start camera preview here.
            mCameraOpenCloseLock.release();//释放访问许可
            mCameraDevice = cameraDevice;//从onOpened参数获取mCameraDevice
            createCameraPreviewSession();//创建会话
        }

        @Override
        public void onDisconnected(@NonNull CameraDevice cameraDevice) {
   //断开相机
            mCameraOpenCloseLock.release();
            cameraDevice.close();
            mCameraDevice = null;
        }

        @Override
        public void onError(@NonNull CameraDevice cameraDevice, int error) {
   //打开错误
            mCameraOpenCloseLock.
;