Android examples for Graphics:Canvas
Convert coordination of face point to screen rect that will be draw on canvas
//package com.java2s; import android.graphics.Matrix; import android.graphics.Point; import java.util.LinkedList; import java.util.List; public class Main { /** 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) {//from w ww . j a va2 s .co m 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; } private static Matrix createConvertMatrix(boolean frontCamera, float displayOrientation, float viewWidth, float viewHeight) { Matrix matrix = new Matrix(); boolean mirror = frontCamera; matrix.setScale(mirror ? -1 : 1, 1); matrix.postRotate(displayOrientation); matrix.postScale(viewWidth / 2000f, viewHeight / 2000f); matrix.postTranslate(viewWidth / 2f, viewHeight / 2f); return matrix; } }