當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。