我希望当我按下按钮 btlento 时相机闪光灯会缓慢闪烁,因为我制作了这些变量:
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;
}