List of usage examples for android.hardware Camera getParameters
public Parameters getParameters()
From source file:Main.java
/** Sets the camera's picture size to the maximum available size, as determined by number of pixels (width*height). * Returns a Camera.Size object containing the updated picture size. *///from w w w . ja v a2s .c o m public static Camera.Size setLargestCameraSize(Camera camera) { Camera.Parameters params = camera.getParameters(); List<Camera.Size> pictureSizes = pictureSizesForCameraParameters(params); if (pictureSizes != null && pictureSizes.size() > 0) { long bestPixels = -1; Camera.Size bestSize = null; for (Camera.Size size : pictureSizes) { long pixels = size.width * size.height; if (pixels > bestPixels || bestPixels < 0) { bestPixels = pixels; bestSize = size; } } if (bestSize != null) { params.setPictureSize(bestSize.width, bestSize.height); camera.setParameters(params); } } return params.getPictureSize(); }
From source file:Main.java
public static Camera openFlightLight() { try {/* ww w . java 2 s. 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
/** 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 . j a 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
static android.hardware.Camera.Parameters getFailsafeCameraParameters(Camera camera) { android.hardware.Camera.Parameters parameters = camera.getParameters(); if (Build.VERSION.SDK_INT >= 9) { setFocusMode(parameters);//from www. j av a 2 s.c om } return parameters; }
From source file:Main.java
@SuppressLint("NewApi") public static List<Size> getCameraSupportedVideoSizes(android.hardware.Camera camera) { if ((Build.VERSION.SDK_INT >= 11) && (camera != null)) { return camera.getParameters().getSupportedVideoSizes(); } else {//w w w .java2 s. co m return null; } }
From source file:Main.java
/** Returns true if the device's API and camera supports zooming. */ public static boolean cameraSupportsZoom(Camera camera) { if (!sdkSupportsCameraZoom()) return false; try {/*from w w w. j av a 2 s . com*/ Camera.Parameters params = camera.getParameters(); Method zoomSupported = params.getClass().getMethod("isZoomSupported"); return (Boolean) zoomSupported.invoke(params); } catch (Exception ex) { return false; } }
From source file:Main.java
public static void setFlashMode(Camera mCamera, Context item, int type) { Camera.Parameters params = mCamera.getParameters(); List<String> FlashModes = params.getSupportedFlashModes(); switch (type) { case 0://from w w w .j av a2 s . c om if (FlashModes.contains(Camera.Parameters.FLASH_MODE_AUTO)) params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); else Toast.makeText(item, "Auto Mode not supported", Toast.LENGTH_SHORT).show(); break; case 1: if (FlashModes.contains(Camera.Parameters.FLASH_MODE_OFF)) params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); else Toast.makeText(item, "Off Mode not supported", Toast.LENGTH_SHORT).show(); break; case 2: if (FlashModes.contains(Camera.Parameters.FLASH_MODE_ON)) params.setFlashMode(Camera.Parameters.FLASH_MODE_ON); else Toast.makeText(item, "On Mode not supported", Toast.LENGTH_SHORT).show(); break; case 3: if (FlashModes.contains(Camera.Parameters.FLASH_MODE_RED_EYE)) params.setFlashMode(Camera.Parameters.FLASH_MODE_RED_EYE); else Toast.makeText(item, "Red Eye Mode not supported", Toast.LENGTH_SHORT).show(); break; case 4: if (FlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); else Toast.makeText(item, "Torch Mode not supported", Toast.LENGTH_SHORT).show(); break; } mCamera.setParameters(params); }
From source file:Main.java
/** Attempts to allocate and register the given number of preview callback buffers. Uses the camera's current preview * size to determine the size of the buffers. If the Android API doesn't support preview buffers, does nothing. * Returns true if successful./*from w w w . j a v a2 s. co m*/ */ public static boolean createPreviewCallbackBuffers(Camera camera, int nbuffers) { if (addPreviewBufferMethod == null) return false; Camera.Size previewSize = camera.getParameters().getPreviewSize(); // 12 bits per pixel for preview buffer (8 chroma bytes, then average of 2 bytes each for Cr and Cb) int bufferSize = previewSize.width * previewSize.height * 3 / 2; for (int i = 0; i < nbuffers; i++) { byte[] buffer = new byte[bufferSize]; try { addPreviewBufferMethod.invoke(camera, buffer); } catch (Exception ignored) { return false; } } return true; }
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 w w w.j ava2 s .c o m } }
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);/*from www .j a v a 2 s. c om*/ } }