Android Open Source - AndroidCameraView Picture Size






From Project

Back to project page AndroidCameraView.

License

The source code is released under:

MIT License

If you think the Android project AndroidCameraView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tatuas.android.cameraview;
/*from w w w . j  a  v a 2  s . co m*/
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.hardware.Camera;

public class PictureSize {
    public int width;
    public int height;

    public PictureSize() {
        this.width = 0;
        this.height = 0;
    }

    public PictureSize(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public enum AspectRatio {
        NORMAL, WIDE, OTHER
    }

    public static class MyComp implements Comparator<Camera.Size> {
        @Override
        public int compare(Camera.Size lhs, Camera.Size rhs) {
            return Double.valueOf(rhs.width * rhs.height).compareTo(Double.valueOf(
                    lhs.width * lhs.height));
        }
    }

    public void setSize(Camera.Size size) {
        size.width = this.width;
        size.height = this.height;
    }

    public static PictureSize getMaxSizeByAspectRatio(List<Camera.Size> cameraSizes,
            AspectRatio aspect) {
        List<Camera.Size> markSizes = new ArrayList<Camera.Size>();
        for (Camera.Size s : cameraSizes) {
            if (aspect != null) {
                if (getAspectRatio(s.width, s.height).equals(aspect)) {
                    markSizes.add(s);
                }
            }
        }

        Collections.sort(markSizes, new MyComp());
        return new PictureSize(markSizes.get(0).width, markSizes.get(0).height);
    }

    public static AspectRatio getAspectRatio(int width, int height) {
        double area = Double.valueOf(width).doubleValue()
                / Double.valueOf(height).doubleValue();
        BigDecimal decimal = new BigDecimal(String.valueOf(area));
        double k1 = decimal.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();

        if (k1 == 1.8) {
            return AspectRatio.WIDE;
        } else if (k1 == 1.3) {
            return AspectRatio.NORMAL;
        } else {
            return AspectRatio.OTHER;
        }
    }
}




Java Source Code List

com.tatuas.android.cameraview.AfterShutterListener.java
com.tatuas.android.cameraview.BeforeShutterListener.java
com.tatuas.android.cameraview.CameraFailedListener.java
com.tatuas.android.cameraview.CameraLayout.java
com.tatuas.android.cameraview.CameraType.java
com.tatuas.android.cameraview.CameraView.java
com.tatuas.android.cameraview.Options.java
com.tatuas.android.cameraview.PictureMaker.java
com.tatuas.android.cameraview.PictureSize.java
com.tatuas.android.cameraview.PictureType.java
com.tatuas.android.cameraview.ShutterFailedListener.java
com.tatuas.android.cameraview.Shutter.java
com.tatuas.android.cameraview.Thumbnail.java
com.tatuas.android.cameraview.Util.java
com.tatuas.android.cameraview.sample.CameraLayoutSampleActivity.java
com.tatuas.android.cameraview.sample.CameraViewSampleActivity.java