当前位置: 首页>>代码示例>>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;未经允许,请勿转载。