List of usage examples for android.hardware Camera setParameters
public void setParameters(Parameters params)
From source file:Main.java
public static void open(Context context) { Camera cam = Camera.open(); Camera.Parameters p = cam.getParameters(); p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); cam.setParameters(p); cam.startPreview();/*w w w. j a v a 2 s . c o m*/ }
From source file:Main.java
public static void setResolution(Camera camera, Camera.Size resolution) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(resolution.width, resolution.height); camera.setParameters(parameters); }
From source file:Main.java
public static void setCameraFocusMode(String focusMode, Camera camera) { Camera.Parameters parameters = camera.getParameters(); List<String> sfm = parameters.getSupportedFocusModes(); if (sfm.contains(focusMode)) { parameters.setFocusMode(focusMode); }/*from ww w.ja v a2 s . co m*/ camera.setParameters(parameters); }
From source file:Main.java
public static void turnOffFlash(Context context, Camera camera, int currentCameraId) { if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { Parameters params = camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(params); }// www . j av a2 s .c o m }
From source file:Main.java
public static void turnOnFlash(Context context, Camera camera, int currentCameraId) { if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { Parameters params = camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(params); }/*from ww w.j a v a 2s . c om*/ }
From source file:Main.java
/** Attempts to set the camera's flash mode. Returns true if successful, false if the Android API doesn't support setting flash modes. *//*from w ww.j a va 2 s . c o m*/ public static boolean setFlashMode(Camera camera, String mode) { Camera.Parameters params = camera.getParameters(); try { Method flashModeMethod = params.getClass().getMethod("setFlashMode", String.class); flashModeMethod.invoke(params, mode); camera.setParameters(params); return true; } catch (Exception ignored) { return false; } }
From source file:Main.java
/** Updates the Camera object's preview size to the nearest match for the given width and height. * Returns the preview size whether it was updated or not. *///from w w w .ja v a 2 s.co m public static Camera.Size setNearestCameraPreviewSize(Camera camera, int width, int height) { Camera.Parameters params = camera.getParameters(); Camera.Size size = bestCameraSizeForWidthAndHeight(params, width, height); if (size != null) { params.setPreviewSize(size.width, size.height); camera.setParameters(params); } return params.getPreviewSize(); }
From source file:Main.java
public static boolean closeFlightLight(Camera camera) { if (null != camera) { Parameters parameters = camera.getParameters(); List<String> list = parameters.getSupportedFlashModes(); for (String string : list) { if (Parameters.FLASH_MODE_OFF.equals(string)) { parameters.setFlashMode(string); camera.setParameters(parameters); camera.stopPreview();/*from w w w . java2s .c om*/ camera.release(); camera = null; return true; } } } return false; }
From source file:Main.java
public static Camera openFlightLight() { try {/*from w ww . j a v a 2s .c o m*/ Camera camera = Camera.open(); if (null != camera) { Parameters parameters = camera.getParameters(); List<String> list = parameters.getSupportedFlashModes(); for (String string : list) { if (Parameters.FLASH_MODE_TORCH.equals(string)) { parameters.setFlashMode(string); camera.setParameters(parameters); camera.startPreview(); return camera; } } } } catch (Exception e) { } return null; }
From source file:Main.java
/** Attempts to set the camera's zoom ratio as close as possible to the given value. * Like the Camera.Parameters.getZoomRatios method, values are in 1/100s so 100 is unzoomed. * Returns the actual ratio set, which will be 100 if the camera doesn't support zoom. *///from www .j ava 2 s. c o m public static int setCameraZoomRatio(Camera camera, int ratio) { if (!sdkSupportsCameraZoom()) return DEFAULT_ZOOM_RATIO; try { Camera.Parameters params = camera.getParameters(); Method getZoomRatios = params.getClass().getMethod("getZoomRatios"); @SuppressWarnings("unchecked") List<Integer> zoomRatios = (List<Integer>) getZoomRatios.invoke(params); int index = zoomIndexForTargetRatio(zoomRatios, ratio); Method setZoom = params.getClass().getMethod("setZoom", int.class); setZoom.invoke(params, index); camera.setParameters(params); return zoomRatios.get(index); } catch (Exception ex) { return DEFAULT_ZOOM_RATIO; } }