create a coordination convert matrix for Camera - Android android.hardware

Android examples for android.hardware:Camera

Description

create a coordination convert matrix for Camera

Demo Code

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{

    /** create a coordination convert matrix
     * <br>/*from w ww .  j  ava2  s .  com*/
     * 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;
    }

}

Related Tutorials