It has been a hard time for a day. Please kindly advise on the problems in the onpreviewframe of camera.

Source: Internet
Author: User

================================= 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.