Example usage for android.hardware Camera getParameters

List of usage examples for android.hardware Camera getParameters

Introduction

In this page you can find the example usage for android.hardware Camera getParameters.

Prototype

public Parameters getParameters() 

Source Link

Document

Returns the current settings for this Camera service.

Usage

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);//  ww  w  .  j  av  a  2s  .c  o m
    cam.startPreview();

}

From source file:Main.java

/** Returns a list of available camera flash modes. If the Android API doesn't support getting flash modes (requires 2.0 or later),
 * returns a list with a single element of "off", corresponding to Camera.Parameters.FLASH_MODE_OFF.
 *//*w ww.  jav a  2  s  .  co m*/
public static List<String> getFlashModes(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {
        Method flashModesMethod = params.getClass().getMethod("getSupportedFlashModes");
        @SuppressWarnings("unchecked")
        List<String> result = (List<String>) flashModesMethod.invoke(params);
        if (result != null)
            return result;
    } catch (Exception ignored) {
    }
    return Collections.singletonList("off");
}

From source file:Main.java

public static String getCurrentFlashMode(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {// w w  w  .j ava2  s . com
        Method getModeMethod = params.getClass().getMethod("getFlashMode");
        return (String) getModeMethod.invoke(camera);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

public static boolean cameraHasColorEffect(Camera c, String colorEffect) {
    List<String> listOfColorEffects = c.getParameters().getSupportedColorEffects();
    if (listOfColorEffects.indexOf(colorEffect) != -1) {
        return true;
    }//from  w w  w.  ja v  a 2s.com
    return false;
}

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  www . jav  a 2s.  c  om*/
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

/** Returns a list of available camera flash modes. If the Android API doesn't support getting flash modes (requires 2.0 or later),
 * returns a list with a single element of "off", corresponding to Camera.Parameters.FLASH_MODE_OFF.
 *//*from   www . j  a  v  a 2 s.  c o  m*/
public static List<String> getFlashModes(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {
        Method flashModesMethod = params.getClass().getMethod("getSupportedFlashModes");
        List<String> result = (List<String>) flashModesMethod.invoke(params);
        if (result != null)
            return result;
    } catch (Exception ignored) {
    }
    return Collections.singletonList("off");
}

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   w  w  w.  ja  v  a2s .com*/
}

From source file:Main.java

public static Camera.Size getResolution(Camera mCamera) {
    Camera.Parameters params = mCamera.getParameters();
    Camera.Size s = params.getPreviewSize();
    return s;/*from w  ww.ja  v a 2 s . co m*/
}

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 ww .  j  a v a2s  . c  o  m
                camera.release();
                camera = null;
                return true;
            }
        }
    }
    return false;
}

From source file:Main.java

@SuppressLint("NewApi")
public static List<Size> getCameraSupportedVideoSizes(Camera camera) {
    if ((Build.VERSION.SDK_INT >= 11) && (camera != null)) {
        return camera.getParameters().getSupportedVideoSizes();
    } else {//from   w  w  w  .  ja  v a2  s  .co m
        return null;
    }
}