List of usage examples for android.hardware Camera getParameters
public Parameters getParameters()
From source file:Main.java
public static Point getCameraResolution(Context context, Camera camera) { return findBestPreviewSizeValue(camera.getParameters(), getScreenResolution(context)); }
From source file:Main.java
public static void setFocusMode(Camera mCamera, Context item, int type) { Camera.Parameters params = mCamera.getParameters(); List<String> FocusModes = params.getSupportedFocusModes(); switch (type) { case 0://ww w . jav a 2 s . c o m if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); else Toast.makeText(item, "Auto Mode not supported", Toast.LENGTH_SHORT).show(); break; case 1: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); else Toast.makeText(item, "Continuous Mode not supported", Toast.LENGTH_SHORT).show(); break; case 2: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_EDOF)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_EDOF); else Toast.makeText(item, "EDOF Mode not supported", Toast.LENGTH_SHORT).show(); break; case 3: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_FIXED)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED); else Toast.makeText(item, "Fixed Mode not supported", Toast.LENGTH_SHORT).show(); break; case 4: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); else Toast.makeText(item, "Infinity Mode not supported", Toast.LENGTH_SHORT).show(); break; case 5: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_MACRO)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO); else Toast.makeText(item, "Macro Mode not supported", Toast.LENGTH_SHORT).show(); break; } mCamera.setParameters(params); }
From source file:Main.java
static android.hardware.Camera.Parameters getMainCameraParameters(Camera camera) { android.hardware.Camera.Parameters parameters = camera.getParameters(); if (Build.VERSION.SDK_INT >= 9) { setFocusMode(parameters);/* www. j a va 2 s . c o m*/ } if (Build.VERSION.SDK_INT > 13) { setAutoExposureLock(parameters); } if (Build.VERSION.SDK_INT > 7) { try { if (parameters.getMaxExposureCompensation() != 0 || parameters.getMinExposureCompensation() != 0) { parameters.setExposureCompensation(0); } } catch (Throwable ignored) { } } return parameters; }
From source file:Main.java
@SuppressLint("NewApi") public static List<Size> getCameraSupportedVideoSizes(android.hardware.Camera camera) { if (camera != null) { if ((Build.VERSION.SDK_INT >= 11) && camera.getParameters().getSupportedVideoSizes() != null) { return camera.getParameters().getSupportedVideoSizes(); } else {/*from w w w .j a va2 s . co m*/ // Video sizes may be null, which indicates that all the supported // preview sizes are supported for video recording. HashSet<String> allSizesLiteral = new HashSet<>(); for (Camera.Size sz : camera.getParameters().getSupportedPreviewSizes()) { allSizesLiteral.add(String.format("%dx%d", sz.width, sz.height)); } // on Samsung Galaxy 3, the supported preview sizes are too many, // but it seems that not all of them can be used as recording video size. // the following set are used by the built-in camera app. Camera.Size[] preferredSizes = { camera.new Size(1920, 1080), camera.new Size(1280, 720), camera.new Size(720, 480), camera.new Size(640, 480), camera.new Size(320, 240) }; List<Size> result = new ArrayList<>(preferredSizes.length); for (Camera.Size sz : preferredSizes) { if (allSizesLiteral.contains(String.format("%dx%d", sz.width, sz.height))) result.add(sz); } return result; } } else { return null; } }
From source file:ac.blitz.acme.video.VideoCaptureDeviceInfoAndroid.java
private static String getDeviceInfo() { try {//from w w w .j av a 2 s . com JSONArray devices = new JSONArray(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); String uniqueName = deviceUniqueName(i, info); JSONObject cameraDict = new JSONObject(); devices.put(cameraDict); List<Size> supportedSizes; List<int[]> supportedFpsRanges; try { Camera camera = Camera.open(i); Parameters parameters = camera.getParameters(); supportedSizes = parameters.getSupportedPreviewSizes(); supportedFpsRanges = parameters.getSupportedPreviewFpsRange(); camera.release(); Log.d(TAG, uniqueName); } catch (RuntimeException e) { Log.e(TAG, "Failed to open " + uniqueName + ", skipping"); continue; } JSONArray sizes = new JSONArray(); for (Size supportedSize : supportedSizes) { JSONObject size = new JSONObject(); size.put("width", supportedSize.width); size.put("height", supportedSize.height); sizes.put(size); } // Android SDK deals in integral "milliframes per second" // (i.e. fps*1000, instead of floating-point frames-per-second) so we // preserve that through the Java->C++->Java round-trip. int[] mfps = supportedFpsRanges.get(supportedFpsRanges.size() - 1); cameraDict.put("name", uniqueName); cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation) .put("sizes", sizes).put("min_mfps", mfps[Parameters.PREVIEW_FPS_MIN_INDEX]) .put("max_mfps", mfps[Parameters.PREVIEW_FPS_MAX_INDEX]); } String ret = devices.toString(2); return ret; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Camera.Size findClosetPreviewSize(Camera camera, Point preferSize) { int preferX = preferSize.x; int preferY = preferSize.y; Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> allSupportSizes = parameters.getSupportedPreviewSizes(); Log.d(TAG, "all support preview size: " + dumpPreviewSizeList(allSupportSizes)); int minDiff = Integer.MAX_VALUE; int index = 0; for (int i = 0; i < allSupportSizes.size(); i++) { Camera.Size size = allSupportSizes.get(i); int x = size.width; int y = size.height; int diff = Math.abs(x - preferX) + Math.abs(y - preferY); if (diff < minDiff) { minDiff = diff;//w ww .ja v a 2 s . c o m index = i; } } Camera.Size size = allSupportSizes.get(index); return size; }
From source file:Main.java
public static boolean isFlashSupported(Camera camera) { /* Credits: Top answer at http://stackoverflow.com/a/19599365/868173 */ if (camera != null) { Camera.Parameters parameters = camera.getParameters(); if (parameters.getFlashMode() == null) { return false; }/*from ww w . j a v a 2s.c o m*/ List<String> supportedFlashModes = parameters.getSupportedFlashModes(); if (supportedFlashModes == null || supportedFlashModes.isEmpty() || supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) { return false; } } else { return false; } return true; }
From source file:Main.java
public static int[] findClosestFpsRange(Camera camera, int minFrameRate, int maxFrameRate) { minFrameRate *= 1000;/*w ww . jav a 2 s . co m*/ maxFrameRate *= 1000; Camera.Parameters parameters = camera.getParameters(); int minIndex = 0; int minDiff = Integer.MAX_VALUE; List<int[]> rangeList = parameters.getSupportedPreviewFpsRange(); Log.d(TAG, "support preview fps range list: " + dumpFpsRangeList(rangeList)); for (int i = 0; i < rangeList.size(); i++) { int[] fpsRange = rangeList.get(i); if (fpsRange.length != 2) { continue; } int minFps = fpsRange[0] / 1000; int maxFps = fpsRange[1] / 1000; int diff = Math.abs(minFps - minFrameRate) + Math.abs(maxFps - maxFrameRate); if (diff < minDiff) { minDiff = diff; minIndex = i; } } int[] result = rangeList.get(minIndex); return result; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static List<Camera.Size> getCameraSupportedVideoSizes(Camera camera) { if ((Build.VERSION.SDK_INT >= 11) && (camera != null)) { // return camera.getParameters().getSupportedVideoSizes(); List<Camera.Size> sizes = camera.getParameters().getSupportedVideoSizes(); if (sizes != null) return camera.getParameters().getSupportedPreviewSizes(); else {/* w w w .j a va 2 s . co m*/ return null; } } else { 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 w w w. j a v a 2 s .co 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; } }