本文整理匯總了Java中android.hardware.Camera.Parameters.setFlashMode方法的典型用法代碼示例。如果您正苦於以下問題:Java Parameters.setFlashMode方法的具體用法?Java Parameters.setFlashMode怎麽用?Java Parameters.setFlashMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.hardware.Camera.Parameters
的用法示例。
在下文中一共展示了Parameters.setFlashMode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: turnLightOff
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* 通過設置Camera關閉閃光燈
*
* @param mCamera
*/
public void turnLightOff() {
if (camera == null) {
return;
}
Parameters parameters = camera.getParameters();
if (parameters == null) {
return;
}
List<String> flashModes = parameters.getSupportedFlashModes();
String flashMode = parameters.getFlashMode();
// Check if camera flash exists
if (flashModes == null) {
return;
}
// 閃光燈打開狀態
if (!Parameters.FLASH_MODE_OFF.equals(flashMode)) {
// Turn off the flash
if (flashModes.contains(Parameters.FLASH_MODE_OFF)) {
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
} else {
Log.e(TAG, "FLASH_MODE_OFF not supported");
}
}
}
示例2: setFlash
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
public void setFlash(boolean flag) {
if (this.mCamera != null && CameraUtils.isFlashSupported(this.mCamera)) {
Parameters parameters = this.mCamera.getParameters();
if (flag) {
if (!parameters.getFlashMode().equals("torch")) {
parameters.setFlashMode("torch");
} else {
return;
}
} else if (!parameters.getFlashMode().equals("off")) {
parameters.setFlashMode("off");
} else {
return;
}
this.mCamera.setParameters(parameters);
}
}
示例3: setFlashState
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/** Turns the LED on or off if phone has one. */
public synchronized void setFlashState(boolean state) {
Log.d("flash", "flash called");
// If the camera has already been opened, we apply the change immediately
if (mCamera != null) {
Log.d("flash", "camera not null");
if (mStreaming && mMode == MODE_MEDIARECORDER_API) {
lockCamera();
}
Parameters parameters = mCamera.getParameters();
// We test if the phone has a flash
if (parameters.getFlashMode()==null) {
// The phone has no flash or the choosen camera can not toggle the flash
throw new RuntimeException("Can't turn the flash on !");
} else {
parameters.setFlashMode(state?Parameters.FLASH_MODE_TORCH:Parameters.FLASH_MODE_OFF);
try {
mCamera.setParameters(parameters);
mFlashEnabled = state;
} catch (RuntimeException e) {
mFlashEnabled = false;
throw new RuntimeException("Can't turn the flash on !");
} finally {
if (mStreaming && mMode == MODE_MEDIARECORDER_API) {
unlockCamera();
}
}
}
} else {
mFlashEnabled = state;
}
}
示例4: setFlashMode
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* 設置閃光燈類型
* @param flashMode
*/
@Override
public void setFlashMode(FlashMode flashMode) {
if(mCamera==null) return;
mFlashMode = flashMode;
Parameters parameters=mCamera.getParameters();
switch (flashMode) {
case ON:
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
break;
case AUTO:
parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
break;
case TORCH:
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
break;
default:
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
break;
}
mCamera.setParameters(parameters);
}
示例5: setFlashLightNormal
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
public static void setFlashLightNormal(boolean active) {
if (camera == null)
camera = getCamera();
Parameters params = camera.getParameters();
if (active) {
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview(); // 開始亮燈;
} else {
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.stopPreview(); // 關掉亮燈
camera.release(); // 關掉照相機
camera =null;
}
ZogUtils.printLog(FlashlightManager.class, "setFlashLightNormal active:" + active);
}
示例6: getCameraInstance
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* A safe way to get an instance of the Camera object.
*/
public Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open(cameraId); // attempt to get a Camera instance
} catch (Exception e) {
Log.e(TAG, "Error: Camera not available!");
// Camera is not available (in use or does not exist)
}
Parameters params = c.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
params.setPictureFormat(ImageFormat.JPEG);
params.setJpegQuality(50); // 1-100, 100 best
c.setParameters(params);
return c; // returns null if camera is unavailable
}
示例7: startPreview
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
private void startPreview() {
if (myCamera != null) {
myCamera.stopPreview();
} else {
myCamera = getCameraInstance();
}
Parameters parameters = myCamera.getParameters();
if (canOpenFlash) {
if (camRecordEnabled) {
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
} else {
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
}
parameters.setPreviewFormat(ImageFormat.NV21);
myCamera.setParameters(parameters);
myCamera.setPreviewCallbackWithBuffer(new MyPreview());
myCamera.addCallbackBuffer(mCallbackBuf);
myCamera.startPreview();
}
示例8: prepare
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
public boolean prepare() {
try {
f = new SurfaceTexture(0);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
// f.setDefaultBufferSize(10000, 10000);
// }
// SurfaceHolder h = new SurfaceView(JCL_ApplicationContext.getContext()).getHolder();
//mCamera.setPreviewDisplay(h);
mCamera.setPreviewTexture(f);
} catch (IOException e1) {
Log.e("JCLCAMERA", e1.getMessage());
return false;
}
Parameters params = mCamera.getParameters();
params.setPreviewSize(width, height);
params.setPictureSize(width, height);
params.setJpegQuality(50);
params.setFlashMode(Parameters.FLASH_MODE_OFF);
params.setPictureFormat(ImageFormat.JPEG);
mCamera.setParameters(params);
return true;
}
示例9: turnLightOn
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
public static void turnLightOn(Camera mCamera) {
if (mCamera == null) {
return;
}
Parameters parameters = mCamera.getParameters();
if (parameters == null) {
return;
}
List<String> flashModes = parameters.getSupportedFlashModes();
// Check if camera flash exists
if (flashModes == null) {
// Use the screen as a flashlight (next best thing)
return;
}
String flashMode = parameters.getFlashMode();
Log.i(TAG, "Flash mode: " + flashMode);
Log.i(TAG, "Flash modes: " + flashModes);
if (!Parameters.FLASH_MODE_TORCH.equals(flashMode)) {
// Turn on the flash
if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(parameters);
} else {
}
}
}
示例10: turnOffFlashLight
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* フラッシュライト消燈.
*/
public synchronized void turnOffFlashLight() {
if (mCamera != null && isFlashLightState()) {
Parameters p = mCamera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
mCamera.setParameters(p);
if (!isShow()) {
mCamera.stopPreview();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
mCamera.setPreviewTexture(null);
} catch (IOException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}
mCamera.release();
mParams = null;
mCamera = null;
}
}
mFlashLightState = false;
mUseFlashLight = false;
}
示例11: setBestParameters
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
@UiThread
private Parameters setBestParameters(Camera camera, Parameters params) {
setVideoStabilisation(params);
setFocusMode(params);
params.setFlashMode(FLASH_MODE_OFF);
setPreviewSize(params);
camera.setParameters(params);
return camera.getParameters();
}
示例12: openLight
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* 打開閃光燈
*/
public void openLight() {
if (camera != null) {
Parameters parameter = camera.getParameters();
parameter.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameter);
}
}
示例13: offLight
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* 關閉閃光燈
*/
public void offLight() {
if (camera != null) {
Parameters parameter = camera.getParameters();
parameter.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameter);
}
}
示例14: turnLightOn
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
/**
* 通過設置Camera打開閃光燈
*/
public void turnLightOn() {
if (camera == null) {
return;
}
Parameters parameters = camera.getParameters();
if (parameters == null) {
return;
}
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes == null) {
return;
}
String flashMode = parameters.getFlashMode();
Log.i(TAG, "Flash mode: " + flashMode);
Log.i(TAG, "Flash modes: " + flashModes);
// 閃光燈關閉狀態
if (!Parameters.FLASH_MODE_TORCH.equals(flashMode)) {
// Turn on the flash
if (flashModes.contains(Parameters.FLASH_MODE_TORCH)) {
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
} else {
}
}
}
示例15: toggleFlash
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
public void toggleFlash() {
if (this.mCamera != null && CameraUtils.isFlashSupported(this.mCamera)) {
Parameters parameters = this.mCamera.getParameters();
if (parameters.getFlashMode().equals("torch")) {
parameters.setFlashMode("off");
} else {
parameters.setFlashMode("torch");
}
this.mCamera.setParameters(parameters);
}
}