我希望当我按下按钮时,相机闪光灯会慢慢闪烁,因为我做了这些变量:
int counter = 1;
int deloy = 2000;
int poriod = 2000;
int deloy1 = 1000;
int poriod1 = 2000;
这是带代码的按钮:
case R.id.btlento:
do{
cameraOn();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
cameraOff();
counter = counter+1;
}
},deloy1,poriod1);
Timer timer2 = new Timer();
timer2.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
cameraOn();
}
},deloy,poriod);
}while(counter>=60);
break;
另一个按钮必须更快地闪烁,所以我做了其他变量:
int j = 1;
int delay = 600;
int period = 600;
int delay1 = 300;
int period1 = 600;
这些是带方法的按钮:
case R.id.btrapid:
do{
cameraOn();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
cameraOff();
j = j+1;
}
},delay1,period1);
Timer timer2 = new Timer();
timer2.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
cameraOn();
}
},delay,period);
}while(j>=5);
break;
现在他们眨眼他们永远不会停止,为什么???? 方法cameraOn是:
private void cameraOn() {
// TODO Auto-generated method stub
camera = Camera.open();
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
}
并且cameraOff是:
private void cameraOff() {
// TODO Auto-generated method stub
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.release();
camera = null;
}
答案 0 :(得分:0)
假设counter
和j
未在其他地方修改,您永远不会输入while块,它应该是:
while(counter<=60)
和
while(j<60)