我需要帮助 android camera 2 api 自动闪光。此解决方案适用于一部手机,但不适用于另一部手机。我花了几个小时寻找解决方案,但没有成功。我的拍照代码:pictureTaken = false; if (null == cameraDevice) { Log.e(TAG, "cameraDevice is null"); return; } CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { int width = 1024; int height = 768; cv.setBackground(getResources().getDrawable(R.drawable.fotak_zeleny)); ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1); List<Surface> outputSurfaces = new ArrayList<Surface>(2); outputSurfaces.add(reader.getSurface()); outputSurfaces.add(new Surface(textureView.getSurfaceTexture())); final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(reader.getSurface()); captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO); captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START); if (flashMode == FLASH_AUTO) { captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); } else if (flashMode == FLASH_ON) { captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH); } else if (flashMode == FLASH_OFF) { captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); } // Orientation int rotation = getWindowManager().getDefaultDisplay().getRotation(); captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation)); final File file = new File(fileName); if (file.exists()) { file.delete(); } etc....
3 回答
GCT1015
TA贡献1827条经验 获得超4个赞
您还应该为预览请求设置所选的 AE_MODE,并在用户切换闪光模式时更新它。此外,您需要在高于 LEGACY 级别的任何设备上运行预捕获序列。
仅针对单个静态拍摄请求更改闪光模式将无法正常工作,因为手机没有机会触发预闪以正确计算闪光功率。
看看camera2basic用于运行precapture序列。如果可能,它总是将 AE 模式设置为 AE_MODE_AUTO_FLASH,但相同的代码适用于其他闪光模式(尽管如果闪光灯设置为关闭,您可以跳过预捕捉序列,通常,只要对焦质量正常)。
添加回答
举报
0/150
提交
取消