List of usage examples for android.hardware Camera setParameters
public void setParameters(Parameters params)
From source file:edu.winlab.minijarvis.activity.CameraActivity.java
/** * To get camera instance/*from w w w .jav a2s . c om*/ * @return Camera */ private static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); // Work around for Camera preview issues Camera.Parameters params = camera.getParameters(); params.setPreviewFpsRange(30000, 30000); camera.setParameters(params); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } return camera; }
From source file:at.wada811.utils.CameraUtils.java
/** * ?// ww w .j av a 2 s. c om * * @param camera * @param pictureSize */ public static void setPictureSize(Camera camera, Size pictureSize) { Parameters params = camera.getParameters(); params.setPictureSize(pictureSize.width, pictureSize.height); camera.setParameters(params); }
From source file:at.wada811.utils.CameraUtils.java
/** * ???/* w w w. j a va2s.c om*/ * * @param camera * @param previewSize */ public static void setPreviewSize(Camera camera, Size previewSize) { Parameters params = camera.getParameters(); params.setPreviewSize(previewSize.width, previewSize.height); camera.setParameters(params); }
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. *//* www.j a v a2 s .co 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
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static void focusOnTouch(Camera camera, MotionEvent event) { Rect focusRect = calculateTapArea(camera, event.getRawX(), event.getRawY(), 1f); Rect meteringRect = calculateTapArea(camera, event.getRawX(), event.getRawY(), 1.5f); Camera.Parameters parameters = camera.getParameters(); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); int version = Build.VERSION.SDK_INT; if (version > Build.VERSION_CODES.ICE_CREAM_SANDWICH && parameters.getMaxNumFocusAreas() > 0) { List<Camera.Area> focusAreas = new ArrayList<Camera.Area>(); focusAreas.add(new Camera.Area(focusRect, 1000)); parameters.setFocusAreas(focusAreas); }/*from w w w . j a v a2 s . c o m*/ if (version > Build.VERSION_CODES.ICE_CREAM_SANDWICH && parameters.getMaxNumMeteringAreas() > 0) { List<Camera.Area> meteringAreas = new ArrayList<Camera.Area>(); meteringAreas.add(new Camera.Area(meteringRect, 1000)); parameters.setMeteringAreas(meteringAreas); } camera.setParameters(parameters); }
From source file:edu.mit.mobile.android.livingpostcards.CameraActivity.java
/** A safe way to get an instance of the Camera object. */ public static Camera getCameraInstance() { Camera c = null; try {// ww w . j av a 2 s. c o m c = Camera.open(); // attempt to get a Camera instance final Parameters params = c.getParameters(); final Size s = getBestPictureSize(640, 480, params); params.setPictureSize(s.width, s.height); if (Constants.DEBUG) { Log.d(TAG, "best picture size is " + s.width + "x" + s.height); } c.setParameters(params); } catch (final Exception e) { Log.e(TAG, "Error acquiring camera", e); } return c; // returns null if camera is unavailable }
From source file:me.hammarstrom.imagerecognition.activities.MainActivity.java
/** * Helper method to get {@link Camera} instance * * @return camera//from w ww .java2 s. c o m */ private Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); // Set auto focus mode Camera.Parameters parameters = camera.getParameters(); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); camera.setParameters(parameters); } catch (Exception e) { // cannot get camera or does not exist } return camera; }
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:/*w w w. j ava 2s. c o m*/ 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
public static boolean setOptimalCameraPreviewSize(Camera camera, int width, int height) { if (camera == null) { return false; }//from w w w .ja v a2 s . c om double targetRatio = (double) height / width; Camera.Parameters params = camera.getParameters(); List<Camera.Size> sizes = params.getSupportedPreviewSizes(); Camera.Size optimalSize = null; // selecting optimal camera preview size int minDiff = Integer.MAX_VALUE; for (Camera.Size size : sizes) { double ratio = (double) size.height / size.width; if (Math.abs(ratio - targetRatio) > RATIO_TOLERANCE) continue; if (Math.abs(size.height - height) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - height); } } if (optimalSize == null) { minDiff = Integer.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - height) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - height); } } } params.setPreviewSize(optimalSize.width, optimalSize.height); List<String> focusModes = params.getSupportedFocusModes(); if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } // for Mi3, only support ImageFormat.NV21 // for most cameras, ImageFormat.NV21 are support worldwide // so use default preview format // params.setPreviewFormat(ImageFormat.JPEG); camera.setParameters(params); return true; }
From source file:com.googlecode.android_scripting.facade.CameraFacade.java
@Rpc(description = "Take a picture and save it to the specified path.", returns = "A map of Booleans autoFocus and takePicture where True " + "indicates success. cameraId also included.") public Bundle cameraCapturePicture(@RpcParameter(name = "targetPath") final String targetPath, @RpcParameter(name = "useAutoFocus") @RpcDefault("true") Boolean useAutoFocus, @RpcParameter(name = "cameraId", description = "Id of camera to use. SDK 9") @RpcDefault("0") Integer cameraId) throws Exception { final BooleanResult autoFocusResult = new BooleanResult(); final BooleanResult takePictureResult = new BooleanResult(); Camera camera = openCamera(cameraId); if (camera == null) { String msg = String.format("can't initialize camera id %d, try to use another id", cameraId); Log.e(msg);//from w w w . j a v a 2s . c o m Bundle result = new Bundle(); result.putInt("cameraId", cameraId); result.putBoolean("autoFocus", false); result.putBoolean("takePicture", false); result.putString("reason", msg + ", see logcat for details"); return result; } Parameters prm = camera.getParameters(); camera.setParameters(prm); try { Method method = camera.getClass().getMethod("setDisplayOrientation", int.class); method.invoke(camera, 90); } catch (Exception e) { Log.e(e); } try { FutureActivityTask<SurfaceHolder> previewTask = setPreviewDisplay(camera); camera.startPreview(); if (useAutoFocus) { autoFocus(autoFocusResult, camera); } takePicture(new File(targetPath), takePictureResult, camera); previewTask.finish(); } catch (Exception e) { Log.e(e); } finally { camera.release(); } Bundle result = new Bundle(); result.putBoolean("autoFocus", autoFocusResult.mmResult); result.putBoolean("takePicture", takePictureResult.mmResult); result.putInt("cameraId", cameraId); return result; }