首页  编辑  

安卓中使用GLCamera的简单方法

Tags: /Android/   Date Created:
如果要使用GLCamera,简单的方法是,使用一个扩展包,在App gradle中,添加一行
implementation 'com.guo.android_extend:android-extend:1.0.6'
然后在你的Layout中,添加一个CameraGLSurfaceView
<com.guo.android_extend.widget.CameraGLSurfaceView
android:id="@+id/glsurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
然后在Activity的代码实现GLSurfaceView的接口
public class DetecterActivity extends Activity implements OnCameraListener
在Activity onCreate中初始化
mGLSurfaceView = (CameraGLSurfaceView) findViewById(R.id.glsurfaceView);
mGLSurfaceView.setOnTouchListener(this);
mSurfaceView = (CameraSurfaceView) findViewById(R.id.surfaceView);
mSurfaceView.setOnCameraListener(this);
mSurfaceView.setupGLSurafceView(mGLSurfaceView, true, mCameraMirror, mCameraRotate);
mSurfaceView.debug_print_fps(true, false);
并重载onPreview,在onPreview中可以拿到相机数据
public Object onPreview(byte[] data, int width, int height, int format, long timestamp) {