Android examples for android.hardware:Camera State
convert Face Point
import android.graphics.Matrix; import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; import android.hardware.Camera; import android.hardware.Camera; import java.util.LinkedList; import java.util.List; public class Main { /**/*from w w w.j av a2 s . co m*/ * Convert coordination of face point to screen rect that will be draw on * canvas<br> */ public static List<Point> convertFacePoint(boolean frontCamera, float displayOrientation, float viewWidth, float viewHeight, Point... points) { Matrix matrix = createConvertMatrix(frontCamera, displayOrientation, viewWidth, viewHeight); float[] pts = new float[points.length * 2]; for (int i = 0; i < points.length; ++i) { pts[i * 2] = points[i].x; pts[i * 2 + 1] = points[i].y; } matrix.mapPoints(pts); List<Point> result = new LinkedList<>(); for (int j = 0; j < pts.length; j += 2) { result.add(new Point((int) pts[j], (int) pts[j + 1])); } return result; } /** * create a coordination convert matrix <br> * See also {@link android.hardware.Camera.Face#rect} */ private static Matrix createConvertMatrix(boolean frontCamera, float displayOrientation, float viewWidth, float viewHeight) { Matrix matrix = new Matrix(); // Need mirror for front camera. boolean mirror = frontCamera; matrix.setScale(mirror ? -1 : 1, 1); // This is the value for android.hardware.Camera.setDisplayOrientation. matrix.postRotate(displayOrientation); // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). // UI coordinates range from (0, 0) to (width, height). matrix.postScale(viewWidth / 2000f, viewHeight / 2000f); matrix.postTranslate(viewWidth / 2f, viewHeight / 2f); return matrix; } }