George Mincila
George Mincila

Reputation: 529

Android camera not focusing. Crash when I try to setParameters

Ok, so I am using the metaio sdk, that launches the camera view. All works fine, but on the Galaxy S4 phone the camera is very blurry and also seems zoomed in. This is only happening on the Galaxy S4, on other devices the camera looks good.

When I try to set the camera parameters by adding this to my activity:

@Override
public void onSurfaceChanged(int width, int height)
{
    super.onSurfaceChanged(width, height);
    Camera camera = metaioSDK.getCamera(this);

    Camera.Parameters parameters = camera.getParameters();
    Log.d("LEE","camera focused?"+parameters.getFocusMode());
    parameters.setFocusMode("continuous-picture");
    Log.d("LEE","camera focused?"+parameters.getFocusMode());
    camera.setParameters(parameters);

}

and I get a crash with these errors:

11-23 20:09:04.693: E/metaio-java(30060): Error in JavaScript: 
11-23 20:09:04.693: E/metaio-java(30060): Error in JavaScript: 
11-23 20:09:04.693: E/metaio-java(30060): Error in JavaScript: 
11-23 20:09:04.693: E/metaio-java(30060): Error in JavaScript: 
11-23 20:09:04.693: E/metaio-java(30060): Error in JavaScript: 
11-23 20:09:04.693: E/metaio-java(30060): Error in JavaScript: 
11-23 20:09:04.693: A/libc(30060): Fatal signal 11 (SIGSEGV) at 0x37333866 (code=1), thread 30146 (WebViewCoreThre)

Also if I try to set the focus mode in onSurfaceCreated(), I get no crash, but the camera view is still blurry.

public void onSurfaceCreated()
    {
        super.onSurfaceCreated();
        Camera camera = metaioSDK.getCamera(this);

        Camera.Parameters parameters = camera.getParameters();
        //Log.d("LEE","camera focused?"+parameters.getFocusMode());
        parameters.setFocusMode("continuous-picture");
        //Log.d("LEE","camera focused?"+parameters.getFocusMode());
        camera.setParameters(parameters);

    }

Any idea on why this is happening and how I can make it focus on the S4 also? How come acting different on different devices?

Upvotes: 1

Views: 1118

Answers (1)

Comrade
Comrade

Reputation: 119

Call Autofocus manually Whenever you want focus

Sample

 preview.camera.autoFocus(new AutoFocusCallback()
{
 @Override
  public void onAutoFocus(boolean arg0,Camera arg1)
  {
    preview.camera.takePicture(shutterCallback,
                                        rawCallback, jpegCallback);
 }
});

Upvotes: 1

Related Questions