How to use flash without stopping camera feed?

2019-07-27 14:21发布

问题:

I am currently working on a barcode scanning app, which uses the mobile vision api for the majority of processes. I am trying to implement a flash button so that a user may scan in low light, but for some reason the activation of flash freezes the camera feed. Is there some way to start flash with a button while the feed is active? To activate flash without interfering with other threads? Thanks!

回答1:

i used this code in my custom camera Application.when User clicks the FlashOn Button then Flash will be start.i think this code will help to you.

try this code (OnButton Click) :

private void btnFlashOnClick() {

if (mCamera != null) {
                // First get the Camera Parameters.
                Camera.Parameters parameters = mCamera.getParameters();

                // set FlashMode to camera parameters.
                parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);

                // set Parameters Objects to Camera.
                mCamera.setParameters(parameters);

                // Finally, Start the Preview Of a Camera
                mCamera.startPreview(); // this Line is Usefull for MyApp.If you don't need then Remove this Line.
            }
}

this code is works fine in my App..Hope this will helps you...(:



回答2:

It really depends what camera api you are using as there are few.

CameraManager has void setTorchMode (String cameraId, boolean enabled) that lets you operate flash regardless of current state of the camera (and without a need to restart one), but it could be overridden by other apps too