使用andar for android方法来冻结相机

时间:2012-08-01 19:34:42

标签: android camera andar

我会解释一下情况。我正试图找出当标记出现时如何暂停相机。我在这个链接中显示了标记的含义。

http://code.google.com/p/andar/

当标记出现时,我想要一种暂停相机的方法,这样即使相机移动,标记也不会消失。我需要这样,所以在玩游戏时相机可以慢跑,但标记仍然会保持在正确的位置。以下是标记活动的代码

公共类CustomActivity扩展了AndARActivity {

CustomObject2 someObject;
ARToolkit artoolkit;
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    CustomRenderer renderer = new CustomRenderer();//optional, may be set to null
    super.setNonARRenderer(renderer);//or might be omited
    try {
        //register a object for each marker type
        artoolkit = super.getArtoolkit();
        someObject = new CustomObject2
            ("test", "patt.hiro", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
        someObject = new CustomObject2
        ("test", "android.patt", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
        someObject = new CustomObject2
        ("test", "barcode.patt", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
    } catch (AndARException ex){
        //handle the exception, that means: show the user what happened
        System.out.println("");
    }       
    startPreview();
}

/**
 * Inform the user about exceptions that occurred in background threads.
 * This exception is rather severe and can not be recovered from.
 * TODO Inform the user and shut down the application.
 */
public void uncaughtException(Thread thread, Throwable ex) {
    Log.e("AndAR EXCEPTION", ex.getMessage());
    finish();
}

}

@覆盖

绘制用于绘制立方体的函数

public final void draw(GL10 gl) {
        super.draw(gl);

        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR,mat_flash);
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mat_flash_shiny);    
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat_diffuse);  
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat_ambient);

        //this code draws the cube. 
        gl.glColor4f(0, 1.0f, 0, 1.0f);
        gl.glTranslatef( 0.0f, 0.0f, 12.5f );


        // experement with the api
        //draw the box
      box.draw(gl);
    }

我会在startPreview函数周围包装代码吗?或者我是否需要检查是否绘制了对象,然后以这种方式停止预览。

我找到了这个命令,但我不确定如何在显示标记时实现它。我知道我需要一些条件但不确定它是什么。 camera.stopPreview();

1 个答案:

答案 0 :(得分:2)

也许尝试添加一些会停止发送相机预览缓冲区进行处理的代码。这样它将继续渲染相机预览,但不会处理新的帧。