在我的代码中,退出线程后,闪光灯仍然亮着。我无法理解逻辑错误。如何在线程结束时关闭闪光灯?
Thread thread = new Thread((new Runnable() {
@Override
public void run() {
SystemClock.sleep(200);
int led = 1;
while (blink_enabler) {
if (led == 1) {
params = cam.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cam.setParameters(params);
cam.startPreview();
led = 0;
} else {
params = cam.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(params);
cam.stopPreview();
led = 1;
}
SystemClock.sleep(1000);
}
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.stopPreview();
}
}));
最佳答案
在while循环之后,在stopPreview()
之前设置摄像机的参数:
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(params);
cam.stopPreview();
关于java - 如何在Android中制作手电筒闪烁,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44852222/