transfer Camera Area From Outer Size - Android Camera

Android examples for Camera:Camera Size

Description

transfer Camera Area From Outer Size

Demo Code


//package com.java2s;

import android.graphics.Point;
import android.graphics.Rect;

public class Main {
    public static Rect transferCameraAreaFromOuterSize(Point center,
            Point outerSize, int size) {
        int left = clampAreaCoord((int) (center.x / (float) (outerSize.x)
                * 2000 - 1000), size);//ww w  .jav  a 2s  .  c  om
        int top = clampAreaCoord((int) (center.y / (float) (outerSize.y)
                * 2000 - 1000), size);

        return new Rect(left, top, left + size, top + size);
    }

    private static int clampAreaCoord(int center, int focusAreaSize) {
        int result;
        if (Math.abs(center) + focusAreaSize / 2 > 1000) {
            if (center > 0) {
                result = 1000 - focusAreaSize / 2;
            } else {
                result = -1000 + focusAreaSize / 2;
            }
        } else {
            result = center - focusAreaSize / 2;
        }
        return result;
    }
}

Related Tutorials