Note that there are some explanatory texts on larger screens.

plurals
  1. POFailed to take picture using auto-focus
    primarykey
    data
    text
    <p>I have searched some solutions with my problem and sure there are many related issues regarding it but nothing solves my concern.</p> <p>I am receiving a runtime exception : <code>takepicture failed:native_autofocus</code>..etc.</p> <p>I tried to take picture from camera using autofocus and I can't seem to understand what could have caused the error. </p> <p>Here is my code.</p> <pre><code>public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mholder; private Camera mcamera; private Handler handler = new Handler(); public CameraPreview(Context context, Camera camera) { super(context); this.mcamera = camera; mholder = getHolder(); mholder.addCallback(this); mholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (mholder.getSurface() == null) { return; } try { mcamera.stopPreview(); } catch (Exception e) { Log.d("surfaceChanged", e.toString()); } try { mcamera.setPreviewDisplay(holder); mcamera.startPreview(); } catch (IOException e) { Log.d("surfaceChanged---&gt;surfaceCreated", e.toString()); } } </code></pre> <p>I think somethings is lacking in my runnable code, I tried to omit the runnable and execute autofocus once, it removed the runtime error. Did I missed to reinitialize something in this part?</p> <pre><code> private void autoFocus(Camera mcamera){ final Camera cam=mcamera; handler.postDelayed(new Runnable() { @Override public void run() { cam.autoFocus(autoFocusCallback); handler.postDelayed(this, 1500L); } }, 1500L); } AutoFocusCallback autoFocusCallback=new AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { camera.takePicture(null, null, mPicture); } }; private PictureCallback mPicture=new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { //do something } }; @Override public void surfaceCreated(SurfaceHolder holder) { try { mcamera.setPreviewDisplay(holder); mcamera.startPreview(); mcamera.autoFocus(autoFocusCallback); } catch (IOException e) { Log.d("surfaceCreated", e.toString()); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload