Custom Zoom On Google Glass, Image captured is not what preview shows

137 views Asked by At

So I successfully implemented my own zoom feature on the Google Glass because right now Google did not add this feature. It looks like so:

@Override
public boolean onFling( MotionEvent e1, MotionEvent e2, float velocityX, float velocityY ) 
{
    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setPreviewFpsRange(30000, 30000);
    int zoom = parameters.getZoom();

    if ( velocityX < 0.0f )
    {
        zoom -= 10;
        if ( zoom < 0 )
            zoom = 0;
    }
    else if ( velocityX > 0.0f )
    {
        zoom += 10;
        if ( zoom > parameters.getMaxZoom() )
            zoom = parameters.getMaxZoom();
    }

    mCamera.startSmoothZoom(zoom);

    return false;
}

Then I detect if the surface changed and call a preview function to update the preview on the screen:

 private void initPreview(int width, int height) 
{
    if ( mCamera != null && mPreviewHolder.getSurface() != null) {
        try 
        {
            mCamera.setPreviewDisplay(mPreviewHolder);
        }
        catch (Throwable t) 
        {
            Log.e(TAG, "Exception in initPreview()", t);
            Toast.makeText(CameraZoom.this, t.getMessage(), Toast.LENGTH_LONG).show();
        }

        if ( !mCameraConfigured ) 
        {
            Camera.Parameters parameters = mCamera.getParameters();
            parameters.setPreviewFpsRange(30000, 30000);
            parameters.setPreviewSize(1920, 1080); // hard coded the largest size for now
            mCamera.setParameters(parameters);
            mCamera.enableShutterSound(true); 
            mCamera.setZoomChangeListener(this);

            mCameraConfigured = true;
        }
    }
}

The problem is when I call the camera to take the picture, it takes a picture of the preview that is significantly above where the preview is at. The height is not getting set to the preview parameters or something I am not sure. This is is the call to capture:

public void onClick(View v)
{
    mCamera.takePicture(null, null, capturedIt);
}

and captureIt is just a PictureCallback. So in summary the image in the preview is not the one being captured by the camera. Any help would be much appreciated.

0

There are 0 answers