当前位置: 首页>>代码示例>>Java>>正文


Java CameraManager.openCamera方法代码示例

本文整理汇总了Java中android.hardware.camera2.CameraManager.openCamera方法的典型用法代码示例。如果您正苦于以下问题:Java CameraManager.openCamera方法的具体用法?Java CameraManager.openCamera怎么用?Java CameraManager.openCamera使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.camera2.CameraManager的用法示例。


在下文中一共展示了CameraManager.openCamera方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readyCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
public void readyCamera() {
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        String pickedCamera = getCamera(manager);
        if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        manager.openCamera(pickedCamera, cameraStateCallback, null);
        imageReader = ImageReader.newInstance(videoWidth, videoHeight, 0x00000001 /*ImageFormat.YUV_420_888*/, 2 /* images buffered */);
        imageReader.setOnImageAvailableListener(onImageAvailableListener, null);
        Log.i(TAG, "imageReader created");
    } catch (CameraAccessException e){
        Log.e(TAG, e.getMessage());
    }
}
 
开发者ID:galme,项目名称:ROLF-EV3,代码行数:23,代码来源:PCVideoStreamer.java

示例2: open

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
public void open() {
    try {
        CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
                StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                mCameraSize = map.getOutputSizes(SurfaceTexture.class)[0];

                HandlerThread thread = new HandlerThread("OpenCamera");
                thread.start();
                Handler backgroundHandler = new Handler(thread.getLooper());

                manager.openCamera(cameraId, mCameraDeviceCallback, null);

                // カメラの物理的な情報を得る
                mCameraCharacteristics = manager.getCameraCharacteristics( cameraId );
                return;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jphacks,项目名称:TK_1701,代码行数:25,代码来源:Camera2.java

示例3: SimpleCamera2

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
SimpleCamera2(Context context, String deviceName) {
  cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  looperThread = new LooperThread();
  looperThread.start();
  looperThread.waitToStart();
  cameraDeviceLock = new Object();
  openDoneSignal = new CountDownLatch(1);
  cameraDevice = null;
  Logging.d(TAG, "Opening simple camera2.");
  try {
    cameraManager.openCamera(deviceName, new CameraStateCallback(), looperThread.getHandler());
  } catch (CameraAccessException e) {
    fail("Simple camera2 CameraAccessException: " + e.getMessage());
  }

  Logging.d(TAG, "Waiting for simple camera2 to open.");
  ThreadUtils.awaitUninterruptibly(openDoneSignal);
  synchronized (cameraDeviceLock) {
    if (!openSucceeded) {
      fail("Opening simple camera2 failed.");
    }
  }
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:24,代码来源:Camera2CapturerTest.java

示例4: openCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void openCamera() {

        CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

        Log.d(TAG, "openCamera Start");
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
            try {
                cameraId = manager.getCameraIdList()[0];

                // setup the camera perview.  should wrap this in a checkpermissions, which studio is bitching about
                // except it has been done before this fragment is called.
                manager.openCamera(cameraId, mStateCallback, null);

            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        } else {
            Log.e(TAG, "Don't have permission to camera!");
        }
        Log.d(TAG, "openCamera End");
    }
 
开发者ID:JimSeker,项目名称:AudioVideo,代码行数:22,代码来源:Cam2Fragment.java

示例5: connectCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void connectCamera() {
    CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) ==
                    PackageManager.PERMISSION_GRANTED) {
                cameraManager.openCamera(mCameraId, mCameraDeviceStateCallback, mBackgroundHandler);
            } else {
                if(shouldShowRequestPermissionRationale(android.Manifest.permission.CAMERA)) {
                    Toast.makeText(this,
                            "Video app required access to camera", Toast.LENGTH_SHORT).show();
                }
                requestPermissions(new String[] {android.Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO
                }, REQUEST_CAMERA_PERMISSION_RESULT);
            }

        } else {
            cameraManager.openCamera(mCameraId, mCameraDeviceStateCallback, mBackgroundHandler);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:mobapptuts,项目名称:android_camera2_api_video_app,代码行数:24,代码来源:Camera2VideoImageActivity.java

示例6: startPreview

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
@SuppressLint({"NewApi", "MissingPermission, UseCheckPermission"})
@SuppressWarnings({"ResourceType"})
public void startPreview(boolean isFlashOn)
//-----------------------
{
   if (cameraWidth < 0 || cameraHeight < 0)
      return;
   this.isFlashOn = isFlashOn;
   CameraManager manager = (CameraManager) surfaceView.getContext().getSystemService(Context.CAMERA_SERVICE);
   if (manager == null)
      return;
   try
   {
      cameraThread = new HandlerThread("CameraPreview");
      cameraThread.start();
      cameraHandler = new Handler(cameraThread.getLooper());
      manager.openCamera(cameraID, cameraStateCallback, cameraHandler);
   }
   catch (Exception e)
   {
      Log.e(LOGTAG, "", e);
      throw new RuntimeException(e);
   }
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:26,代码来源:PreviewCamera.java

示例7: init

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void init(Context context) throws CameraAccessException {
  inSession = false;

  if (!ImageSaver.isExternalStorageWritable()) {
    Timber.e("Cannot save file, external storage is not writable.");
    return;
  }

  File root = ImageSaver.getRoot(ROBOCAR_FOLDER);
  if (root == null) {
    Timber.e("Failed to create destination folder.");
    return;
  }

  CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  String[] cameras = manager.getCameraIdList();
  if (cameras.length == 0) {
    Timber.e("No cameras available.");
    return;
  }

  Timber.d("Default camera selected (%s), %d cameras found.",
      cameras[CAMERA_INDEX], cameras.length);

  if (ActivityCompat.checkSelfPermission(
      context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    Timber.d("Camera permission not granted yet, restart your device.");
    return;
  }

  // Debug and check for autofocus support
  dumpFormatInfo(manager, cameras[CAMERA_INDEX]);

  startBackgroundThread();
  deviceCallback = new DeviceCallback();
  manager.openCamera(cameras[CAMERA_INDEX], deviceCallback, backgroundHandler);
}
 
开发者ID:zugaldia,项目名称:android-robocar,代码行数:38,代码来源:CameraOperator.java

示例8: initializeCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Initialize the camera device
 */
public void initializeCamera(Context context,
                             Handler backgroundHandler,
                             ImageReader.OnImageAvailableListener imageAvailableListener) {
    // Discover the camera instance
    CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    String[] camIds = {};
    try {
        camIds = manager.getCameraIdList();
    } catch (CameraAccessException e) {
        Log.d(TAG, "Cam access exception getting IDs", e);
    }
    if (camIds.length < 1) {
        Log.d(TAG, "No cameras found");
        return;
    }
    String id = camIds[0];
    Log.d(TAG, "Using camera id " + id);
    // Initialize the image processor
    mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
            ImageFormat.JPEG, MAX_IMAGES);
    mImageReader.setOnImageAvailableListener(
            imageAvailableListener, backgroundHandler);
    // Open the camera resource
    try {
        manager.openCamera(id, mStateCallback, backgroundHandler);
    } catch (CameraAccessException cae) {
        Log.d(TAG, "Camera access exception", cae);
    }
}
 
开发者ID:googlecodelabs,项目名称:androidthings-imageclassifier,代码行数:33,代码来源:CameraHandler.java

示例9: initializeCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Initialize the camera device
 */
@SuppressLint("MissingPermission")
public void initializeCamera(Context context,
                             Handler backgroundHandler,
                             ImageReader.OnImageAvailableListener imageAvailableListener) {
    // Discover the camera instance
    CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
    String[] camIds = {};
    try {
        camIds = manager.getCameraIdList();
    } catch (CameraAccessException e) {
        Timber.e(e, "Cam access exception getting IDs");
    }
    if (camIds.length < 1) {
        Timber.d("No cameras found");
        return;
    }
    String id = camIds[0];
    Timber.d("Using camera id %s", id);

    // Initialize the image processor
    mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
            ImageFormat.JPEG, MAX_IMAGES);
    mImageReader.setOnImageAvailableListener(
            imageAvailableListener, backgroundHandler);

    // Open the camera resource
    try {
        manager.openCamera(id, mStateCallback, backgroundHandler);
    } catch (CameraAccessException cae) {
        Timber.e(cae, "Camera access exception");
    }
}
 
开发者ID:leinardi,项目名称:androidthings-kuman-sm9,代码行数:36,代码来源:Camera.java

示例10: initializeCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Initialize the camera device
 */
void initializeCamera(@NonNull Context context,
                      @NonNull Handler backgroundHandler,
                      @NonNull ImageReader.OnImageAvailableListener imageAvailableListener) {
    mBackgroundHandler = backgroundHandler;

    // Discover the camera instance
    CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
    String[] camIds = {};
    try {
        camIds = manager.getCameraIdList();
    } catch (CameraAccessException e) {
        Log.e(TAG, "Cam access exception getting IDs", e);
    }
    if (camIds.length < 1) {
        Log.e(TAG, "No cameras found");
        return;
    }
    String id = camIds[0];
    Log.d(TAG, "Using camera id " + id);

    // Initialize the image processor
    mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT, ImageFormat.JPEG, MAX_IMAGES);
    mImageReader.setOnImageAvailableListener(imageAvailableListener, backgroundHandler);

    // Open the camera resource
    try {
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            Log.d(TAG, "initializeCamera: Camera permission not available.");
            return;
        }
        manager.openCamera(id, mStateCallback, backgroundHandler);
    } catch (CameraAccessException cae) {
        Log.d(TAG, "Camera access exception", cae);
    }
}
 
开发者ID:kevalpatel2106,项目名称:robo-car,代码行数:39,代码来源:PiCameraDriver.java

示例11: initCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void initCamera() {
    cameraID = "" + CameraCharacteristics.LENS_FACING_BACK;
    cameraManager = (CameraManager) getContext().getSystemService(CAMERA_SERVICE);
    try {
        if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getContext(), "请授权使用照相机", Toast.LENGTH_SHORT).show();
            return;
        }
        //$ process in background
        cameraManager.openCamera(cameraID, cameraStateCallback, backGroundHandler1);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:lazyparser,项目名称:xbot_head,代码行数:16,代码来源:SignInFragment.java

示例12: initCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void initCamera() {
    cameraId = "" + CameraCharacteristics.LENS_FACING_BACK;
    cameraManager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);

    try {
        if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getContext(), "没有相机权限", Toast.LENGTH_SHORT).show();
        } else {
            cameraManager.openCamera(cameraId, cameraCallback, backgroundHandler);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

}
 
开发者ID:lazyparser,项目名称:xbot_head,代码行数:16,代码来源:CommentaryFragment.java

示例13: initCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void initCamera() {
    cameraID = "" + CameraCharacteristics.LENS_FACING_BACK;
    cameraManager = (CameraManager) getContext().getSystemService(CAMERA_SERVICE);
    try {
        if (ActivityCompat.checkSelfPermission(getContext(),Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getContext(), "请授权使用照相机", Toast.LENGTH_SHORT).show();
            return;
        }
        cameraManager.openCamera(cameraID, cameraStateCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:lazyparser,项目名称:xbot_head,代码行数:15,代码来源:InteractionFragment.java

示例14: initializeCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Initialize the camera device
 */
public void initializeCamera(Context context,
                             Handler backgroundHandler,
                             ImageReader.OnImageAvailableListener imageAvailableListener) {
    // Discover the camera instance
    CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
    String[] camIds = {};
    try {
        camIds = manager.getCameraIdList();
    } catch (CameraAccessException e) {
        Log.d(TAG, "Cam access exception getting IDs", e);
    }
    if (camIds.length < 1) {
        Log.d(TAG, "No cameras found");
        return;
    }
    String id = camIds[0];
    Log.d(TAG, "Using camera id " + id);

    // Initialize the image processor
    mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
            ImageFormat.JPEG, MAX_IMAGES);
    mImageReader.setOnImageAvailableListener(
            imageAvailableListener, backgroundHandler);

    // Open the camera resource
    try {
        manager.openCamera(id, mStateCallback, backgroundHandler);
    } catch (CameraAccessException cae) {
        Log.d(TAG, "Camera access exception", cae);
    }
}
 
开发者ID:androidthings,项目名称:doorbell,代码行数:35,代码来源:DoorbellCamera.java

示例15: startCapture

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
public boolean startCapture() {
    ThreadUtils.assertOnUiThread();
    changeCameraStateAndNotify(CameraState.OPENING);
    final CameraManager manager =
            (CameraManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.CAMERA_SERVICE);

    if (!mUseBackgroundThreadForTesting) {
        mMainHandler = new Handler(ContextUtils.getApplicationContext().getMainLooper());
    } else {
        // Usually we deliver frames on application context thread, but unit tests
        // occupy its Looper; deliver frames on a background thread instead.
        HandlerThread thread = new HandlerThread("CameraPicture");
        thread.start();
        mMainHandler = new Handler(thread.getLooper());
    }

    final CrStateListener stateListener = new CrStateListener();
    try {
        manager.openCamera(Integer.toString(mId), stateListener, mMainHandler);
    } catch (CameraAccessException | IllegalArgumentException | SecurityException ex) {
        Log.e(TAG, "allocate: manager.openCamera: ", ex);
        return false;
    }

    return true;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:29,代码来源:VideoCaptureCamera2.java


注:本文中的android.hardware.camera2.CameraManager.openCamera方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。