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

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

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

Camera.setParameters介绍

暂无

代码示例

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

Camera cam = Camera.open();     
Parameters p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();

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

@Override
  public void onAutoFocus(boolean success, Camera camera) {
    Camera.Parameters params = camera.getParameters();
    params.setFocusMode(currentFocusMode);
    camera.setParameters(params);
  }
});

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

@Override
void setDisplayOrientation(int displayOrientation) {
  if (mDisplayOrientation == displayOrientation) {
    return;
  }
  mDisplayOrientation = displayOrientation;
  if (isCameraOpened()) {
    mCameraParameters.setRotation(calcCameraRotation(displayOrientation));
    mCamera.setParameters(mCameraParameters);
    final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
    if (needsToStopPreview) {
      mCamera.stopPreview();
    }
    mCamera.setDisplayOrientation(calcDisplayOrientation(displayOrientation));
    if (needsToStopPreview) {
      mCamera.startPreview();
    }
  }
}

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

SurfaceView preview = (SurfaceView) findViewById(R.id.PREVIEW);
SurfaceHolder mHolder = preview.getHolder();
mHolder.addCallback(this);
Camera mCamera = Camera.open();
mCamera.setPreviewDisplay(mHolder);

// Turn on LED  
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);      
mCamera.startPreview();

...

// Turn off LED
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
mCamera.stopPreview();
mCamera.release();

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

void setTorch(Camera camera, boolean newSetting) {
  Camera.Parameters parameters = camera.getParameters();
  doSetTorch(parameters, newSetting, false);
  camera.setParameters(parameters);
}

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

@Override
void setDisplayOrientation(int displayOrientation) {
  if (mDisplayOrientation == displayOrientation) {
    return;
  }
  mDisplayOrientation = displayOrientation;
  if (isCameraOpened()) {
    mCameraParameters.setRotation(calcCameraRotation(displayOrientation));
    mCamera.setParameters(mCameraParameters);
    final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
    if (needsToStopPreview) {
      mCamera.stopPreview();
    }
    mCamera.setDisplayOrientation(calcDisplayOrientation(displayOrientation));
    if (needsToStopPreview) {
      mCamera.startPreview();
    }
  }
}

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

/**
 * 打开闪光灯
 *
 * @return
 */
public static void openFlashLight() {
  try {
    if (camera == null) {
      camera = Camera.open();
      camera.startPreview();
    }
    Camera.Parameters parameters = camera.getParameters();
    parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    camera.setParameters(parameters);
  } catch (Exception e) {
    e.printStackTrace();
  }
}

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

void setTorch(Camera camera, boolean newSetting) {
 Camera.Parameters parameters = camera.getParameters();
 doSetTorch(parameters, newSetting);
 camera.setParameters(parameters);
 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
 boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_TOGGLE_LIGHT, false);
 if (currentSetting != newSetting) {
  SharedPreferences.Editor editor = prefs.edit();
  editor.putBoolean(PreferencesActivity.KEY_TOGGLE_LIGHT, newSetting);
  editor.commit();
 }
}

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

void adjustCameraParameters() {
  SortedSet<Size> sizes = mPreviewSizes.sizes(mAspectRatio);
  if (sizes == null) { // Not supported
    mAspectRatio = chooseAspectRatio();
    sizes = mPreviewSizes.sizes(mAspectRatio);
  }
  Size size = chooseOptimalSize(sizes);
  // Always re-apply camera parameters
  // Largest picture size in this ratio
  final Size pictureSize = mPictureSizes.sizes(mAspectRatio).last();
  if (mShowingPreview) {
    mCamera.stopPreview();
  }
  mCameraParameters.setPreviewSize(size.getWidth(), size.getHeight());
  mCameraParameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
  mCameraParameters.setRotation(calcCameraRotation(mDisplayOrientation));
  setAutoFocusInternal(mAutoFocus);
  setFlashInternal(mFlash);
  mCamera.setParameters(mCameraParameters);
  if (mShowingPreview) {
    mCamera.startPreview();
  }
}

代码示例来源: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: vondear/RxTool

/**
 * 关闭闪光灯
 *
 * @return
 */
public static void closeFlashLight() {
  try {
    if (camera == null) {
    } else {
      Camera.Parameters parameters = camera.getParameters();
      parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
      camera.setParameters(parameters);
      camera.release();
      camera = null;
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}

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

void adjustCameraParameters() {
  SortedSet<Size> sizes = mPreviewSizes.sizes(mAspectRatio);
  if (sizes == null) { // Not supported
    mAspectRatio = chooseAspectRatio();
    sizes = mPreviewSizes.sizes(mAspectRatio);
  }
  Size size = chooseOptimalSize(sizes);
  // Always re-apply camera parameters
  // Largest picture size in this ratio AspectRatio.parse(aspectRatio)
  SortedSet<Size> sizeSortedSet = mPictureSizes.sizes(mAspectRatio);
  if (sizeSortedSet == null) {
    sizeSortedSet = mPictureSizes.sizes(AspectRatio.parse("4:3"));
  }
  final Size pictureSize = sizeSortedSet.last();
  if (mShowingPreview) {
    mCamera.stopPreview();
  }
  mCameraParameters.setPreviewSize(size.getWidth(), size.getHeight());
  mCameraParameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
  mCameraParameters.setRotation(calcCameraRotation(mDisplayOrientation));
  setAutoFocusInternal(mAutoFocus);
  setFlashInternal(mFlash);
  mCamera.setParameters(mCameraParameters);
  if (mShowingPreview) {
    mCamera.startPreview();
  }
}

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

mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
for(Camera.Size str: mSupportedPreviewSizes)
    Log.e(TAG, str.width + "/" + str.height);
  Camera.Parameters parameters = mCamera.getParameters();
  parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
  mCamera.setParameters(parameters);
  mCamera.setDisplayOrientation(90);
  mCamera.setPreviewDisplay(mHolder);
  mCamera.startPreview();

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

/**开关闪光灯
 * @param open
 * @return
 */
public boolean switchLight(boolean open) {
  parameter = camera.getParameters();  
  if (open) {
    parameter.setFlashMode(Parameters.FLASH_MODE_TORCH); 
    camera.setParameters(parameter);
    return true;
  } else {
    parameter.setFlashMode(Parameters.FLASH_MODE_OFF); 
    camera.setParameters(parameter);
    return false;
  }
}
//Lemon add >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

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

if (Build.MODEL.equals("GT-P1000")) {

      Log.d(FlashlightActivity.TAG, "This is Samsung Galaxy Tab.");

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

      isLEDturnedOn = true;
      Log.d(FlashlightActivity.TAG, "LED turned ON.");

}

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

} else {
    Parameters param = camera.getParameters();
    param.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    try {
        camera.setParameters(param);
        camera.startPreview();
        isLightOn = true;
    } catch (Exception e) {

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

/**
 * Changes the settings for Camera.
 *
 * @param callback {@link CameraParametersCallback}
 */
public void changeCameraParameters(CameraParametersCallback callback) {
  if (camera != null) {
    try {
      camera.setParameters(callback.changeCameraParameters(camera.getParameters()));
    } catch(RuntimeException e) {
      // Camera error. Could happen if the camera is being closed.
      Log.e(TAG, "Failed to change camera parameters", e);
    }
  }
}

代码示例来源:origin: gumingwei/WellSwipe

public synchronized void on(Context context) {
  if (mCamera == null) {
    open(context);
  }
  if (mCamera != null) {
    isOpen = true;
    mCameraParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    mCamera.setParameters(mCameraParameters);
    mCamera.startPreview();
  }
}

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

parameters = mCamera.getParameters();
} catch (Exception e) {
mCamera.setParameters(parameters);
mCamera.startPreview();
mCamera.autoFocus(myAutoFocusCallback);
mPreviewRunning = true;

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

/**开关闪光灯
 * @param open
 * @return
 */
public boolean switchLight(boolean open) {
  parameter = camera.getParameters();  
  if (open) {
    parameter.setFlashMode(Parameters.FLASH_MODE_TORCH); 
    camera.setParameters(parameter);
    return true;
  } else {
    parameter.setFlashMode(Parameters.FLASH_MODE_OFF); 
    camera.setParameters(parameter);
    return false;
  }
}
//Lemon add >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

相关文章