================================= Problem description ========================== =
Deploy my initialized Functions
protected void initCamre(){camera = Camera.open(0);camera.setDisplayOrientation(90);Camera.Parameters parameters = camera.getParameters();parameters.setPreviewSize(720, 1280);parameters.setPreviewFpsRange(4, 10);parameters.setPictureFormat(ImageFormat.JPEG);parameters.set("jpeg-quelity", 85);parameters.setPictureSize(720, 1280);if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);}int[] textures = new int[1];GLES20.glGenTextures(1, textures, 0);SurfaceTexture surfaceTexture = new SurfaceTexture(textures[0]);try{camera.setPreviewTexture(surfaceTexture);camera.setPreviewCallback(new MyCamera());camera.startPreview();}catch (IOException e){Log.i("tyty", e.toString());e.printStackTrace();}}
Mycamera class
Class mycamera implements previewcallback {@ overridepublic void onpreviewframe (byte [] data, camera) {Camera. parameters PS = camera. getparameters (); int [] IMGs = new int [PS. getpreviewsize (). width * ps. getpreviewsize (). height]; camera. addcallbackbuffer (data); log. I ("tyty", "Callback ");}}
Here, the onpreviewframe callback method will only be executed five times and then no longer executed. Why ???
=============================== Solution 1 ========================== ===
Camera. setpreviewcallback (new camera. previewcallback (){
@ Override
Public void onpreviewframe (byte [] data, camera ){
}
});
// The Code should be correct.
=============================== Solution 2 ========================== ===
Because you are using surfacetexture, the data in surfacetexture will be consumed to fill in new data so that you can capture the Preview Data. After surfacetexture receives the new frame, call surfacetexture. updateteximage () consumes the buffer.
Or you can use surfaceview directly, so you don't have to handle it yourself.
It has been a hard time for a day. Please kindly advise on the problems in the onpreviewframe of camera.