我怎样才能纠正频闪效果

时间:2014-01-06 03:33:58

标签: java android multithreading loops camera

我想创建一个频闪效果,让手电筒闪烁。下面是我的代码,现在我已经实现的是让它闪光但只有一次,这就是为什么我需要帮助我让它闪现很多时间。

public class Strobe extends Activity {

    Camera cam;
    private static final String TAG = null;
    private Handler mHander = new Handler();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        strobe();       
    }

    private void turnOnLight(){
        for(int x = 0; x == 10; x++);{ //although for does exist does nothing and that is in all for i have put around my program,don't know why
            Log.d("tagname","runs 10 times  a");

        cam = Camera.open();
        Parameters params = cam.getParameters();
        params.setFlashMode(Parameters.FLASH_MODE_TORCH);
        cam.setParameters(params);
        cam.startPreview();
        cam.autoFocus(new AutoFocusCallback(){
            public void onAutoFocus(boolean success, Camera camera) {
            }

        });
        }
    }

    private void turnOffLight(){
        for(int x = 0; x == 10; x++);{ 

        cam.stopPreview();
        cam.release();
        Log.d("tagname","runs 10 times  b");

        }
    }

    private void strobe(){
        for(int x = 0; x == 10; x++);{ 
        Thread timer = new Thread(){
            public void run(){


                turnOnLight();
                try{
                    Thread.sleep(300);

                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                turnOffLight();
                Log.d("tagname","runs 10 times  c");


            };      
          };timer.start();
        };

    }

    };

3 个答案:

答案 0 :(得分:0)

您是否考虑过for循环的语法都错了?对于staryers,你正在使用==你可能想要使用<,并且你在for语句之后放了一个分号,其中不应该有一个分号。查看for循环的正确语法并尝试重写代码。

答案 1 :(得分:0)

类似的问题是here: Repeat a task with a time delay?

您可以使用此示例创建可运行的。

答案 2 :(得分:0)

int n=10000;
while(n-->0)
{

int n=100000;
while(n-->0) 
{
turnOnLight();
try{
      Thread.sleep(300);
   }catch(InterruptedException e)
{
      e.printStackTrace();`enter code here`
}
turnOffLight();
Log.d("tagname","runs 10 times  c");
}

}