android.hardware.Camera.autoFocus()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(628)

本文整理了Java中android.hardware.Camera.autoFocus()方法的一些代码示例,展示了Camera.autoFocus()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.autoFocus()方法的具体详情如下:
包路径:android.hardware.Camera
类名称:Camera
方法名:autoFocus

Camera.autoFocus介绍

暂无

代码示例

代码示例来源:origin: rmtheis/android-ocr

synchronized void start() {
  try {
    camera.autoFocus(this);
  } catch (RuntimeException re) {
    // Have heard RuntimeException reported in Android 4.0.x+; continue?
    Log.w(TAG, "Unexpected exception while focusing", re);
  }
}

代码示例来源:origin: dm77/barcodescanner

public void safeAutoFocus() {
  try {
    mCameraWrapper.mCamera.autoFocus(autoFocusCB);
  } catch (RuntimeException re) {
    // Horrible hack to deal with autofocus errors on Sony devices
    // See https://github.com/dm77/barcodescanner/issues/7 for example
    scheduleAutoFocus(); // wait 1 sec and then do check again
  }
}

代码示例来源:origin: TommyLemon/APIJSON

/**
 * Asks the camera hardware to perform an autofocus.
 *
 * @param handler The Handler to notify when the autofocus completes.
 * @param message The message to deliver.
 */
public void requestAutoFocus(Handler handler, int message) {
  if (camera != null && previewing) {
    autoFocusCallback.setHandler(handler, message);
    //Log.d(TAG, "Requesting auto-focus callback");
    camera.autoFocus(autoFocusCallback);
  }
}

代码示例来源:origin: stackoverflow.com

Camera cam;
void ledon() {
  cam = Camera.open();     
  Parameters params = cam.getParameters();
  params.setFlashMode(Parameters.FLASH_MODE_ON);
  cam.setParameters(params);
  cam.startPreview();
  cam.autoFocus(new AutoFocusCallback() {
        public void onAutoFocus(boolean success, Camera camera) {
        }
      });
}

void ledoff() {
  cam.stopPreview();
  cam.release();
}

代码示例来源:origin: yipianfengye/android-zxingLibrary

/**
 * Asks the camera hardware to perform an autofocus.
 *
 * @param handler The Handler to notify when the autofocus completes.
 * @param message The message to deliver.
 */
public void requestAutoFocus(Handler handler, int message) {
  if (camera != null && previewing) {
    autoFocusCallback.setHandler(handler, message);
    //Log.d(TAG, "Requesting auto-focus callback");
    camera.autoFocus(autoFocusCallback);
  }
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

/**
 * Asks the camera hardware to perform an autofocus.
 *
 * @param handler The Handler to notify when the autofocus completes.
 * @param message The message to deliver.
 */
public void requestAutoFocus(Handler handler, int message) {
  if (camera != null && previewing) {
    autoFocusCallback.setHandler(handler, message);
    //Log.d(TAG, "Requesting auto-focus callback");
    camera.autoFocus(autoFocusCallback);
  }
}

代码示例来源:origin: journeyapps/zxing-android-embedded

private void focus() {
  if (useAutoFocus) {
    if (!stopped && !focusing) {
      try {
        camera.autoFocus(autoFocusCallback);
        focusing = true;
      } catch (RuntimeException re) {
        // Have heard RuntimeException reported in Android 4.0.x+; continue?
        Log.w(TAG, "Unexpected exception while focusing", re);
        // Try again later to keep cycle going
        autoFocusAgainLater();
      }
    }
  }
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

synchronized void start() {
  if (useAutoFocus) {
    outstandingTask = null;
    if (!stopped && !focusing) {
      try {
        camera.autoFocus(this);
        focusing = true;
      } catch (RuntimeException re) {
        // Have heard RuntimeException reported in Android 4.0.x+; continue?
        Log.w(TAG, "Unexpected exception while focusing", re);
        // Try again later to keep cycle going
        autoFocusAgainLater();
      }
    }
  }
}

代码示例来源:origin: googlesamples/android-vision

/**
 * Starts camera auto-focus and registers a callback function to run when
 * the camera is focused.  This method is only valid when preview is active
 * (between {@link #start()} or {@link #start(SurfaceHolder)} and before {@link #stop()} or {@link #release()}).
 * <p/>
 * <p>Callers should check
 * {@link #getFocusMode()} to determine if
 * this method should be called. If the camera does not support auto-focus,
 * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean)}
 * callback will be called immediately.
 * <p/>
 * <p>If the current flash mode is not
 * {@link Camera.Parameters#FLASH_MODE_OFF}, flash may be
 * fired during auto-focus, depending on the driver and camera hardware.<p>
 *
 * @param cb the callback to run
 * @see #cancelAutoFocus()
 */
public void autoFocus(@Nullable AutoFocusCallback cb) {
  synchronized (mCameraLock) {
    if (mCamera != null) {
      CameraAutoFocusCallback autoFocusCallback = null;
      if (cb != null) {
        autoFocusCallback = new CameraAutoFocusCallback();
        autoFocusCallback.mDelegate = cb;
      }
      mCamera.autoFocus(autoFocusCallback);
    }
  }
}

代码示例来源:origin: googlesamples/android-vision

autoFocusCallback.mDelegate = cb;
mCamera.autoFocus(autoFocusCallback);

代码示例来源:origin: googlesamples/android-vision

autoFocusCallback.mDelegate = cb;
camera.autoFocus(autoFocusCallback);

代码示例来源:origin: daniulive/SmarterStreaming

mCamera.autoFocus(myAutoFocusCallback);
mPreviewRunning = true;

代码示例来源:origin: vondear/RxTool

@Override
void takePicture() {
  if (!isCameraOpened()) {
    throw new IllegalStateException(
        "Camera is not ready. Call start() before takePicture().");
  }
  if (getAutoFocus()) {
    mCamera.cancelAutoFocus();
    mCamera.autoFocus(new Camera.AutoFocusCallback() {
      @Override
      public void onAutoFocus(boolean success, Camera camera) {
        takePictureInternal();
      }
    });
  } else {
    takePictureInternal();
  }
}

代码示例来源:origin: daniulive/SmarterStreaming

pushCamera.autoFocus(pushAutoFocusCallback);
pushPreviewRunning = true;

代码示例来源:origin: vondear/RxTool

camera.setParameters(params);
camera.autoFocus(new Camera.AutoFocusCallback() {
  @Override
  public void onAutoFocus(boolean success, Camera camera) {

代码示例来源:origin: google/cameraview

@Override
void takePicture() {
  if (!isCameraOpened()) {
    throw new IllegalStateException(
        "Camera is not ready. Call start() before takePicture().");
  }
  if (getAutoFocus()) {
    mCamera.cancelAutoFocus();
    mCamera.autoFocus(new Camera.AutoFocusCallback() {
      @Override
      public void onAutoFocus(boolean success, Camera camera) {
        takePictureInternal();
      }
    });
  } else {
    takePictureInternal();
  }
}

代码示例来源:origin: daniulive/SmarterStreaming

mCamera.autoFocus(myAutoFocusCallback);
mPreviewRunning = true;

代码示例来源:origin: LaiFeng-Android/SopCastComponent

public boolean doAutofocus(Camera.AutoFocusCallback focusCallback) {
  if(mState != State.PREVIEW || mCameraDevice == null) {
    return false;
  }
  // Make sure our auto settings aren't locked
  Camera.Parameters params = mCameraDevice.getParameters();
  if (params.isAutoExposureLockSupported()) {
    params.setAutoExposureLock(false);
  }
  if (params.isAutoWhiteBalanceLockSupported()) {
    params.setAutoWhiteBalanceLock(false);
  }
  mCameraDevice.setParameters(params);
  mCameraDevice.cancelAutoFocus();
  mCameraDevice.autoFocus(focusCallback);
  return true;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testCancelAutoFocus() {
 assertThat(shadowCamera.hasRequestedAutoFocus()).isFalse();
 camera.autoFocus(null);
 assertThat(shadowCamera.hasRequestedAutoFocus()).isTrue();
 camera.cancelAutoFocus();
 assertThat(shadowCamera.hasRequestedAutoFocus()).isFalse();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testAutoFocus() {
 assertThat(shadowCamera.hasRequestedAutoFocus()).isFalse();
 TestAutoFocusCallback callback = new TestAutoFocusCallback();
 camera.autoFocus(callback);
 assertThat(shadowCamera.hasRequestedAutoFocus()).isTrue();
 shadowCamera.invokeAutoFocusCallback(true, camera);
 assertThat(callback.success).isEqualTo(true);
 assertThat(callback.camera).isEqualTo(camera);
 assertThat(shadowCamera.hasRequestedAutoFocus()).isFalse();
 try {
  shadowCamera.invokeAutoFocusCallback(true, camera);
  fail("expected an IllegalStateException");
 } catch (IllegalStateException e) {
  // expected
 }
}

相关文章