當前位置: 首頁>>代碼示例>>Java>>正文


Java CameraCharacteristics.LENS_FACING_BACK屬性代碼示例

本文整理匯總了Java中android.hardware.camera2.CameraCharacteristics.LENS_FACING_BACK屬性的典型用法代碼示例。如果您正苦於以下問題:Java CameraCharacteristics.LENS_FACING_BACK屬性的具體用法?Java CameraCharacteristics.LENS_FACING_BACK怎麽用?Java CameraCharacteristics.LENS_FACING_BACK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.hardware.camera2.CameraCharacteristics的用法示例。


在下文中一共展示了CameraCharacteristics.LENS_FACING_BACK屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: open

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,代碼行數:24,代碼來源:Camera2.java

示例2: getCameraInfo

@Override
protected String getCameraInfo() {
    String camStr = mContext.getString(R.string.camApi2) + "\n";
    CameraManager camManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String camId : camManager.getCameraIdList()) {
            camStr += mContext.getString(R.string.cameraId, camId) + ": ";

            CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
            Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

            camStr += (hasFlash ? mContext.getString(R.string.has) : mContext.getString(R.string.no))
                    + " " + mContext.getString(R.string.flash) + ", ";
            camStr += (facing == CameraCharacteristics.LENS_FACING_BACK ?
                    mContext.getString(R.string.backFacing) : mContext.getString(R.string.frontFacing)) + "\n";
        }
    } catch (CameraAccessException e) {
        camStr = mActivity.getString(R.string.failedAccessCamera) + ":" + e.getMessage();
    }

    return camStr.trim();
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:23,代碼來源:MotionDetectorCamera2.java

示例3: FlashController

public FlashController(Context ctx, CameraManager cameraManager, ServerConnection serverConnection) throws CameraAccessException, IllegalAccessException {
    mCtx = ctx;
    camManager = cameraManager;
    mServerConnection = serverConnection;

    EventBus.getDefault().register(this);

    for (String camId : camManager.getCameraIdList()) {
        CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
        Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

        if (facing == CameraCharacteristics.LENS_FACING_BACK && hasFlash) {
            torchId = camId;
            break;
        }
    }

    if (torchId == null) {
        throw new IllegalAccessException(ctx.getString(R.string.couldNotFindBackFlash));
    }
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:22,代碼來源:FlashController.java

示例4: toggleFacing

public void toggleFacing() {
  if (facingSelected == CameraCharacteristics.LENS_FACING_FRONT) {
    facingSelected = CameraCharacteristics.LENS_FACING_BACK;
    toggleButton.setImageResource(R.drawable.ic_camera_rear);
  } else {
    facingSelected = CameraCharacteristics.LENS_FACING_FRONT;
    toggleButton.setImageResource(R.drawable.ic_camera_front);
  }

  toggleButton.invalidate();

  closeCamera();
  if (textureView.isAvailable()) {
    openCamera(textureView.getWidth(), textureView.getHeight());
  } else {
    textureView.setSurfaceTextureListener(surfaceTextureListener);
  }
}
 
開發者ID:flipper83,項目名稱:SortingHatAndroid,代碼行數:18,代碼來源:CameraConnectionFragment.java

示例5: getCameraId

private String getCameraId() {
    if (mCameraId == null) {
        try {
            String[] ids = mCameraManager.getCameraIdList();
            for (String id : ids) {
                CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
                Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
                Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
                if (flashAvailable != null && flashAvailable && lensFacing != null &&
                        lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
                    mCameraId = id;
                }
            }
            if (DEBUG) Log.d(TAG, "getCameraId: " + mCameraId);
        } catch (Exception e) {
            e.printStackTrace();
            mTorchStatus = TORCH_STATUS_ERROR;
            broadcastStatus();
            stopSelf();
        }
    }
    return mCameraId;
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:23,代碼來源:TorchService.java

示例6: getCameraId

private String getCameraId() throws CameraAccessException {
    int camera = frontFacingCameraActive ? CameraCharacteristics.LENS_FACING_FRONT
                                         : CameraCharacteristics.LENS_FACING_BACK;
    for (String cameraId : cameraManager.getCameraIdList()) {
        CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);

        if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
                == camera) {
            return cameraId;
        }
    }
    return null;
}
 
開發者ID:team-supercharge,項目名稱:SCCameraView,代碼行數:13,代碼來源:Camera2View.java

示例7: getCameraResolutionsBack

public Size[] getCameraResolutionsBack() {
  try {
    CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics("0");
    if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
        != CameraCharacteristics.LENS_FACING_BACK) {
      cameraCharacteristics = cameraManager.getCameraCharacteristics("1");
    }
    StreamConfigurationMap streamConfigurationMap =
        cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    return streamConfigurationMap.getOutputSizes(SurfaceTexture.class);
  } catch (CameraAccessException e) {
    Log.e(TAG, e.getMessage());
    return new Size[0];
  }
}
 
開發者ID:pedroSG94,項目名稱:rtmp-rtsp-stream-client-java,代碼行數:15,代碼來源:Camera2ApiManager.java

示例8: toggleCamera

private void toggleCamera() {
  Integer lens = mCamera.getCurrentLensFacing();
  switch (lens) {
    case CameraCharacteristics.LENS_FACING_FRONT:
      mCamera.openCamera(CameraCharacteristics.LENS_FACING_BACK);
      break;
    case CameraCharacteristics.LENS_FACING_BACK:
      mCamera.openCamera(CameraCharacteristics.LENS_FACING_FRONT);
      break;
  }
}
 
開發者ID:tkrworks,項目名稱:JinsMemeBRIDGE-Android,代碼行數:11,代碼來源:CameraMenuFragment.java

示例9: getCameraId

private String getCameraId() throws CameraAccessException {
    String[] ids = mCameraManager.getCameraIdList();
    for (String id : ids) {
        CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
        Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
        Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
        if (flashAvailable != null && flashAvailable
                && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
            return id;
        }
    }
    return null;
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:13,代碼來源:FlashlightController.java

示例10: initCamera

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,代碼行數:15,代碼來源:SignInFragment.java

示例11: initCamera

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,代碼行數:15,代碼來源:CommentaryFragment.java

示例12: initCamera

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,代碼行數:14,代碼來源:InteractionFragment.java

示例13: findAndOpenCamera

private void findAndOpenCamera() {
    boolean cameraPermissions = checkCameraPermissions();
    if (cameraPermissions) {
        String errorMessage = "Unknown error";
        boolean foundCamera = false;
        initializeCamera();
        if (cameraPermissions && mCameraOps != null) {
            try {
                // Find first back-facing camera that has necessary capability.
                String[] cameraIds = mCameraManager.getCameraIdList();
                for (String id : cameraIds) {
                    CameraCharacteristics info = mCameraManager.getCameraCharacteristics(id);
                    int facing = info.get(CameraCharacteristics.LENS_FACING);

                    int level = info.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
                    boolean hasFullLevel =
                            (level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);

                    int[] capabilities =
                            info.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
                    int syncLatency = info.get(CameraCharacteristics.SYNC_MAX_LATENCY);
                    boolean hasManualControl =
                            hasCapability(capabilities, CameraCharacteristics
                                    .REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR);
                    boolean hasEnoughCapability = hasManualControl && syncLatency ==
                            CameraCharacteristics.SYNC_MAX_LATENCY_PER_FRAME_CONTROL;

                    // All these are guaranteed by
                    // CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL, but checking
                    // for only the things we care about expands range of devices we can run on.
                    // We want:
                    //  - Back-facing camera
                    //  - Manual sensor control
                    //  - Per-frame synchronization (so that exposure can be changed every
                    // frame)
                    if (facing == CameraCharacteristics.LENS_FACING_BACK &&
                            (hasFullLevel || hasEnoughCapability)) {
                        // Found suitable camera - get info, open, and set up outputs
                        mCameraInfo = info;
                        mCameraOps.openCamera(id);
                        configureSurfaces();
                        foundCamera = true;
                        break;
                    }
                }
                if (!foundCamera) {
                    errorMessage = getString(R.string.camera_no_good);
                }
            } catch (CameraAccessException e) {
                errorMessage = getErrorString(e);
            }
            if (!foundCamera) {
                showErrorDialog(errorMessage);
            }
        }
    }
}
 
開發者ID:lydia-schiff,項目名稱:hella-renderscript,代碼行數:57,代碼來源:BaseViewfinderActivity.java


注:本文中的android.hardware.camera2.CameraCharacteristics.LENS_FACING_BACK屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。