Closed SmallWeiChen closed 3 years ago
你好(Hello): 我是來自台灣(Taiwan)的開發者(Developer) 非常抱歉英文不好所以使用中文 您寫的 QREader 掃描非常好用(QREader very good) 但我的專案需要打開閃光燈(open flash)
import android.hardware.Camera; public void openFlash() { Camera camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); camera.setParameters(parameters); }
為此希望能在 QREader.class 加入 getCamera() 或 openFlash() / closeFlash() (QREader.class add method to getCamera() or openFlash() and closeFlash())
CameraSource cameraSource = new CameraSource.Builder(...)... public Camera getCamera() { Field[] declaredFields = CameraSource.class.getDeclaredFields(); for (Field field : declaredFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { return camera; } return null; } catch (Exception e) { e.printStackTrace(); } break; } } return null; } public void openFlash() { Camera camera = getCamera(); Camera.Parameters parameters = camera.getParameters(); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); camera.setParameters(parameters); } public void closeFlash() { Camera camera = getCamera(); Camera.Parameters parameters = camera.getParameters(); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); camera.setParameters(parameters); }
謝謝您(Thank you)
Closing as issue is outdated. Please open a new issue if the issue still persists.
你好(Hello): 我是來自台灣(Taiwan)的開發者(Developer) 非常抱歉英文不好所以使用中文 您寫的 QREader 掃描非常好用(QREader very good) 但我的專案需要打開閃光燈(open flash)
為此希望能在 QREader.class 加入 getCamera() 或 openFlash() / closeFlash() (QREader.class add method to getCamera() or openFlash() and closeFlash())
謝謝您(Thank you)