FileDocCategorySizeDatePackage
CameraProfile.javaAPI DocAndroid 5.1 API4098Thu Mar 12 22:22:30 GMT 2015android.media

CameraProfile

public class CameraProfile extends Object
The CameraProfile class is used to retrieve the pre-defined still image capture (jpeg) quality levels (0-100) used for low, medium, and high quality settings in the Camera application.

Fields Summary
public static final int
QUALITY_LOW
Define three quality levels for JPEG image encoding.
public static final int
QUALITY_MEDIUM
public static final int
QUALITY_HIGH
private static final HashMap
sCache
Constructors Summary
Methods Summary
private static int[]getImageEncodingQualityLevels(int cameraId)

        System.loadLibrary("media_jni");
        native_init();
    
        int nLevels = native_get_num_image_encoding_quality_levels(cameraId);
        if (nLevels != QUALITY_HIGH + 1) {
            throw new RuntimeException("Unexpected Jpeg encoding quality levels " + nLevels);
        }

        int[] levels = new int[nLevels];
        for (int i = 0; i < nLevels; ++i) {
            levels[i] = native_get_image_encoding_quality_level(cameraId, i);
        }
        Arrays.sort(levels);  // Lower quality level ALWAYS comes before higher one
        return levels;
    
public static intgetJpegEncodingQualityParameter(int quality)
Returns a pre-defined still image capture (jpeg) quality level used for the given quality level in the Camera application for the first back-facing camera on the device. If the device has no back-facing camera, this returns 0.

param
quality The target quality level


                                                    
         
        int numberOfCameras = Camera.getNumberOfCameras();
        CameraInfo cameraInfo = new CameraInfo();
        for (int i = 0; i < numberOfCameras; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
                return getJpegEncodingQualityParameter(i, quality);
            }
        }
        return 0;
    
public static intgetJpegEncodingQualityParameter(int cameraId, int quality)
Returns a pre-defined still image capture (jpeg) quality level used for the given quality level in the Camera application for the specified camera.

param
cameraId The id of the camera
param
quality The target quality level

        if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
            throw new IllegalArgumentException("Unsupported quality level: " + quality);
        }
        synchronized (sCache) {
            int[] levels = sCache.get(cameraId);
            if (levels == null) {
                levels = getImageEncodingQualityLevels(cameraId);
                sCache.put(cameraId, levels);
            }
            return levels[quality];
        }
    
private static final native intnative_get_image_encoding_quality_level(int cameraId, int index)

private static final native intnative_get_num_image_encoding_quality_levels(int cameraId)

private static final native voidnative_init()