100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android usb摄像头 前后置 android – 在后置和前置摄像头之间切换

android usb摄像头 前后置 android – 在后置和前置摄像头之间切换

时间:2023-05-27 21:30:03

相关推荐

android usb摄像头 前后置 android – 在后置和前置摄像头之间切换

我正在使用示例camera2谷歌并运作良好.

但是如何用按钮在后面和前面之间切换相机?

private void setUpCameraOutputs(int width, int height) {

Activity activity = getActivity();

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

try {

for (String cameraId : manager.getCameraIdList()) {

CameraCharacteristics characteristics

= manager.getCameraCharacteristics(cameraId);

// We don't use a front facing camera in this sample. Para trocar, colocar != no lugar de ==.

if (characteristics.get(CameraCharacteristics.LENS_FACING)

== CameraCharacteristics.LENS_FACING_FRONT) {

continue;

}

StreamConfigurationMap map = characteristics.get(

CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

// For still image captures, we use the largest available size.

Size largest = Collections.max(

Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),

new CompareSizesByArea());

mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),

ImageFormat.JPEG, /*maxImages*/2);

mImageReader.setOnImageAvailableListener(

mOnImageAvailableListener, mBackgroundHandler);

// Danger, W.R.! Attempting to use too large a preview size could exceed the camera

// bus' bandwidth limitation, resulting in gorgeous previews but the storage of

// garbage capture data.

mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),

width, height, largest);

// We fit the aspect ratio of TextureView to the size of preview we picked.

int orientation = getResources().getConfiguration().orientation;

if (orientation == Configuration.ORIENTATION_LANDSCAPE) {

mTextureView.setAspectRatio(

mPreviewSize.getWidth(), mPreviewSize.getHeight());

} else {

mTextureView.setAspectRatio(

mPreviewSize.getHeight(), mPreviewSize.getWidth());

}

mCameraId = cameraId;

return;

}

} catch (CameraAccessException e) {

e.printStackTrace();

} catch (NullPointerException e) {

// Currently an NPE is thrown when the Camera2API is used but not supported on the

// device this code runs.

new ErrorDialog().show(getFragmentManager(), "dialog");

}

}

`

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。