Android Utililty Methods Camera Size Get

List of utility methods to do Camera Size Get

Description

The list of methods to do Camera Size Get are organized into topic(s).

Method

SizegetOptimalPreviewSize(List sizes, int w, int h)
get Optimal Preview Size
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
if (sizes == null)
    return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Size size : sizes) {
...
SizegetOptimalPreviewSize(List supportedSizes, int w, int h)
Returns a Size object containing the dimensions for an optimal preview size for the current hardware.
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (supportedSizes == null)
    return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Size size : supportedSizes) {
...
Camera.SizegetOptimalPreviewSize(int displayOrientation, int width, int height, Camera.Parameters parameters)
get Optimal Preview Size
double targetRatio = (double) width / height;
List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = height;
if (displayOrientation == 90 || displayOrientation == 270) {
    targetRatio = (double) height / width;
for (Size size : sizes) {
    double ratio = (double) size.width / size.height;
    if (Math.abs(ratio - targetRatio) <= ASPECT_TOLERANCE) {
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
if (optimalSize == null) {
    minDiff = Double.MAX_VALUE;
    for (Size size : sizes) {
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
return (optimalSize);
Camera.SizegetBiggestPictureSize( Camera.Parameters parameters)
get Biggest Picture Size
Camera.Size result = null;
for (Camera.Size size : parameters.getSupportedPictureSizes()) {
    if (result == null) {
        result = size;
    } else {
        int resultArea = result.width * result.height;
        int newArea = size.width * size.height;
        if (newArea > resultArea) {
...
StringtoString(Iterable areas)
to String
if (areas == null) {
    return null;
StringBuilder result = new StringBuilder();
for (Camera.Area area : areas) {
    result.append(area.rect).append(':').append(area.weight)
            .append(' ');
return result.toString();
Camera.SizegetSmallestPictureSize( Camera.Parameters parameters)
get Smallest Picture Size
Camera.Size result = null;
for (Camera.Size size : parameters.getSupportedPictureSizes()) {
    if (result == null) {
        result = size;
    } else {
        int resultArea = result.width * result.height;
        int newArea = size.width * size.height;
        if (newArea < resultArea) {
...
SizegetUsefulSize(List sizes, int w, int h, int type)
get Useful Size
Size size;
switch (type) {
case SIZE:
    size = getSizeSIZE(sizes, w, h);
    break;
case RATIO:
    size = getSizeRATIO(sizes, w, h);
    break;
...