transfer Camera Area From Outer Size - Android android.hardware

Android examples for android.hardware:Camera Size

Description

transfer Camera Area From Outer Size

Demo Code

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);
    int top = clampAreaCoord((int) (center.y / (float) (outerSize.y) * 2000 - 1000), size);

    return new Rect(left, top, left + size, top + size);
  }/*from w  w w .jav  a 2 s  . c o m*/

  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