Android examples for Camera:Camera Preview
calculate proportional layout dimension for displaying a camera preview according to a given camera preview size
//package com.java2s; import android.hardware.Camera; public class Main { public static int[] getProportionalDimension(Camera.Size size, int targetW, int targetH, boolean isPortrait) { int[] adaptedDimension = new int[2]; double previewRatio; if (isPortrait) { previewRatio = (double) size.height / size.width; } else {/*w w w. ja v a 2 s .c o m*/ previewRatio = (double) size.width / size.height; } if (((double) targetW / targetH) > previewRatio) { adaptedDimension[0] = targetW; adaptedDimension[1] = (int) (adaptedDimension[0] / previewRatio); } else { adaptedDimension[1] = targetH; adaptedDimension[0] = (int) (adaptedDimension[1] * previewRatio); } return adaptedDimension; } }