Android examples for Camera:Camera Feature
update Camera Parameters Preference
import java.util.List; import android.content.Context; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.hardware.Camera.Size; import android.media.CameraProfile; import android.util.Log; public class Main{ public static void updateCameraParametersPreference(Context ctx, Camera cam) {/*from w w w . j a v a 2s . c o m*/ // get Camera parameters Camera.Parameters params = cam.getParameters(); List<String> focusModes = params.getSupportedFocusModes(); if (focusModes .contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { // set the focus mode params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } //set the camera picture size initialCameraPictureSize(ctx, params); // Set JPEG quality. int jpegQuality = CameraProfile.getJpegEncodingQualityParameter(0, CameraProfile.QUALITY_HIGH); params.setJpegQuality(jpegQuality); List<String> flashModes = params.getSupportedFlashModes(); if (flashModes.contains(Camera.Parameters.FLASH_MODE_AUTO)) { // set the focus mode params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); } List<String> whiteBalanceModes = params.getSupportedWhiteBalance(); if (whiteBalanceModes .contains(Camera.Parameters.WHITE_BALANCE_AUTO)) { // set the focus mode params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO); } // set Camera parameters cam.setParameters(params); } public static void initialCameraPictureSize(Context context, Parameters parameters) { // When launching the camera app first time, we will set the picture // size to the first one in the list defined in "arrays.xml" and is also // supported by the driver. List<Size> supported = parameters.getSupportedPictureSizes(); if (supported == null) return; for (String candidate : context.getResources().getStringArray( R.array.pref_camera_picturesize_entryvalues)) { if (setCameraPictureSize(candidate, supported, parameters)) { return; } } } public static boolean setCameraPictureSize(String candidate, List<Size> supported, Parameters parameters) { int index = candidate.indexOf('x'); if (index == -1) return false; int width = Integer.parseInt(candidate.substring(0, index)); int height = Integer.parseInt(candidate.substring(index + 1)); for (Size size : supported) { if (size.width == width && size.height == height) { parameters.setPictureSize(width, height); return true; } } return false; } }