Java Code Examples for android.hardware.Camera#Area

The following examples show how to use android.hardware.Camera#Area . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraConfigurationUtils.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
private static String toString(Iterable<Camera.Area> areas) {
  if (areas == null) {
    return null;
  }
  StringBuilder result = new StringBuilder();
  for (Camera.Area area : areas) {
    result.append(area.rect).append(':').append(area.weight).append(' ');
  }
  return result.toString();
}
 
Example 2
Source File: CameraConfigurationUtils.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
private static String toString(Iterable<Camera.Area> areas) {
    if (areas == null) {
        return null;
    }
    StringBuilder result = new StringBuilder();
    for (Camera.Area area : areas) {
        result.append(area.rect).append(':').append(area.weight).append(' ');
    }
    return result.toString();
}
 
Example 3
Source File: CameraConfigurationUtils.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private static String toString(Iterable<Camera.Area> areas) {
  if (areas == null) {
    return null;
  }
  StringBuilder result = new StringBuilder();
  for (Camera.Area area : areas) {
    result.append(area.rect).append(':').append(area.weight).append(' ');
  }
  return result.toString();
}
 
Example 4
Source File: CameraConfigurationUtils.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
public static void setFocusArea(Camera.Parameters parameters) {
  if (parameters.getMaxNumFocusAreas() > 0) {
    Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas()));
    List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
    Log.i(TAG, "Setting focus area to : " + toString(middleArea));
    parameters.setFocusAreas(middleArea);
  } else {
    Log.i(TAG, "Device does not support focus areas");
  }
}
 
Example 5
Source File: CameraConfigurationUtils.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
public static void setFocusArea(Camera.Parameters parameters) {
    if (parameters.getMaxNumFocusAreas() > 0) {
        Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas()));
        List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
        Log.i(TAG, "Setting focus area to : " + toString(middleArea));
        parameters.setFocusAreas(middleArea);
    } else {
        Log.i(TAG, "Device does not support focus areas");
    }
}
 
Example 6
Source File: CameraConfigurationUtils.java    From CodeScaner with MIT License 5 votes vote down vote up
public static void setMetering(Camera.Parameters parameters) {
  if (parameters.getMaxNumMeteringAreas() > 0) {
    Log.i(TAG, "Old metering areas: " + parameters.getMeteringAreas());
    List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
    Log.i(TAG, "Setting metering area to : " + toString(middleArea));
    parameters.setMeteringAreas(middleArea);
  } else {
    Log.i(TAG, "Device does not support metering areas");
  }
}
 
Example 7
Source File: CameraConfigurationUtils.java    From moVirt with Apache License 2.0 5 votes vote down vote up
public static void setMetering(Camera.Parameters parameters) {
    if (parameters.getMaxNumMeteringAreas() > 0) {
        Log.i(TAG, "Old metering areas: " + parameters.getMeteringAreas());
        List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
        Log.i(TAG, "Setting metering area to : " + toString(middleArea));
        parameters.setMeteringAreas(middleArea);
    } else {
        Log.i(TAG, "Device does not support metering areas");
    }
}
 
Example 8
Source File: ParameterUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Point convertCameraPointToActiveArrayPoint(
        Rect activeArray, ZoomData zoomData, Point point, boolean usePreviewCrop) {
    Rect pointedRect = new Rect(point.x, point.y, point.x, point.y);
    Camera.Area pointedArea = new Area(pointedRect, /*weight*/1);

    WeightedRectangle adjustedRect =
            convertCameraAreaToActiveArrayRectangle(activeArray,
                    zoomData, pointedArea, usePreviewCrop);

    Point transformedPoint = new Point(adjustedRect.rect.left, adjustedRect.rect.top);

    return transformedPoint;
}
 
Example 9
Source File: CameraConfigurationUtils.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public static void setMetering(Camera.Parameters parameters) {
  if (parameters.getMaxNumMeteringAreas() > 0) {
    Log.i(TAG, "Old metering areas: " + parameters.getMeteringAreas());
    List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
    Log.i(TAG, "Setting metering area to : " + toString(middleArea));
    parameters.setMeteringAreas(middleArea);
  } else {
    Log.i(TAG, "Device does not support metering areas");
  }
}
 
Example 10
Source File: CameraConfigurationUtils.java    From CodeScaner with MIT License 5 votes vote down vote up
public static void setFocusArea(Camera.Parameters parameters) {
  if (parameters.getMaxNumFocusAreas() > 0) {
    Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas()));
    List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
    Log.i(TAG, "Setting focus area to : " + toString(middleArea));
    parameters.setFocusAreas(middleArea);
  } else {
    Log.i(TAG, "Device does not support focus areas");
  }
}
 
Example 11
Source File: CameraProxy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
public void focusOnPoint(int x, int y, int width, int height) {
    Log.v(TAG, "touch point (" + x + ", " + y + ")");
    if (mCamera == null) {
        return;
    }
    Parameters parameters = mCamera.getParameters();
    // 1.先要判断是否支持设置聚焦区域
    if (parameters.getMaxNumFocusAreas() > 0) {
        // 2.以触摸点为中心点,view窄边的1/4为聚焦区域的默认边长
        int length = Math.min(width, height) >> 3; // 1/8的长度
        int left = x - length;
        int top = y - length;
        int right = x + length;
        int bottom = y + length;
        // 3.映射,因为相机聚焦的区域是一个(-1000,-1000)到(1000,1000)的坐标区域
        left = left * 2000 / width - 1000;
        top = top * 2000 / height - 1000;
        right = right * 2000 / width - 1000;
        bottom = bottom * 2000 / height - 1000;
        // 4.判断上述矩形区域是否超过边界,若超过则设置为临界值
        left = left < -1000 ? -1000 : left;
        top = top < -1000 ? -1000 : top;
        right = right > 1000 ? 1000 : right;
        bottom = bottom > 1000 ? 1000 : bottom;
        Log.d(TAG, "focus area (" + left + ", " + top + ", " + right + ", " + bottom + ")");
        ArrayList<Camera.Area> areas = new ArrayList<>();
        areas.add(new Camera.Area(new Rect(left, top, right, bottom), 600));
        parameters.setFocusAreas(areas);
    }
    try {
        mCamera.cancelAutoFocus(); // 先要取消掉进程中所有的聚焦功能
        mCamera.setParameters(parameters);
        mCamera.autoFocus(this); // 调用聚焦
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 12
Source File: CameraPreview.java    From RecordVideo with Apache License 2.0 5 votes vote down vote up
public boolean manualFocus(Camera camera, Camera.AutoFocusCallback cb, List<Camera.Area> focusAreas
        ,List<Camera.Area> mFocusAreas) {
    //判断系统是否是4.0以上的版本
    if (camera != null && focusAreas != null && SystemVersionUtil.hasICS()) {
        try {
            camera.cancelAutoFocus();
            Camera.Parameters parameters = camera.getParameters();
            if(parameters != null){
                // getMaxNumFocusAreas检测设备是否支持
                if (parameters.getMaxNumFocusAreas() > 0) {
                    parameters.setFocusAreas(focusAreas);
                }
                // getMaxNumMeteringAreas检测设备是否支持
                if (parameters.getMaxNumMeteringAreas() > 0)
                    parameters.setMeteringAreas(mFocusAreas);
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
                camera.setParameters(parameters);
                camera.autoFocus(cb);
                return true;
            }
        } catch (Exception e) {
            if (e != null)
                Log.e(" ", "autoFocus", e);
        }
    }
    return false;
}
 
Example 13
Source File: RxCameraActionBuilder.java    From RxCamera with MIT License 5 votes vote down vote up
public Observable<RxCamera> areaFocusAction(final List<Camera.Area> focusAreaList) {
    if (focusAreaList == null || focusAreaList.size() == 0) {
        return null;
    }
    return Observable.create(new Observable.OnSubscribe<RxCamera>() {
        @Override
        public void call(final Subscriber<? super RxCamera> subscriber) {
            Camera.Parameters parameters = rxCamera.getNativeCamera().getParameters();
            if (parameters.getMaxNumFocusAreas() < focusAreaList.size()) {
                subscriber.onError(new SettingAreaFocusError(SettingAreaFocusError.Reason.NOT_SUPPORT));
            } else {
                if (parameters.getFocusMode() != Camera.Parameters.FOCUS_MODE_AUTO) {
                    List<String> focusModes = parameters.getSupportedFocusModes();
                    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
                        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
                    }
                }
                parameters.setFocusAreas(focusAreaList);
                rxCamera.getNativeCamera().setParameters(parameters);
                rxCamera.getNativeCamera().autoFocus(new Camera.AutoFocusCallback() {
                    @Override
                    public void onAutoFocus(boolean success, Camera camera) {
                        if (success) {
                            subscriber.onNext(rxCamera);
                        } else {
                            subscriber.onError(new SettingAreaFocusError(SettingAreaFocusError.Reason.SET_AREA_FOCUS_FAILED));
                        }
                    }
                });
            }
        }
    });
}
 
Example 14
Source File: CameraConfigurationUtils.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public static void setFocusArea(Camera.Parameters parameters) {
  if (parameters.getMaxNumFocusAreas() > 0) {
    Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas()));
    List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
    Log.i(TAG, "Setting focus area to : " + toString(middleArea));
    parameters.setFocusAreas(middleArea);
  } else {
    Log.i(TAG, "Device does not support focus areas");
  }
}
 
Example 15
Source File: CameraConfigurationUtils.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
public static void setMetering(Camera.Parameters parameters) {
    if (parameters.getMaxNumMeteringAreas() > 0) {
        Log.i(TAG, "Old metering areas: " + parameters.getMeteringAreas());
        List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
        Log.i(TAG, "Setting metering area to : " + toString(middleArea));
        parameters.setMeteringAreas(middleArea);
    } else {
        Log.i(TAG, "Device does not support metering areas");
    }
}
 
Example 16
Source File: CameraConfigurationUtils.java    From ZXing-Standalone-library with Apache License 2.0 4 votes vote down vote up
private static List<Camera.Area> buildMiddleArea(int areaPer1000) {
  return Collections.singletonList(
      new Camera.Area(new Rect(-areaPer1000, -areaPer1000, areaPer1000, areaPer1000), 1));
}
 
Example 17
Source File: CameraConfigurationUtils.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private static List<Camera.Area> buildMiddleArea(int areaPer1000) {
  return Collections.singletonList(
      new Camera.Area(new Rect(-areaPer1000, -areaPer1000, areaPer1000, areaPer1000), 1));
}
 
Example 18
Source File: CameraConfigurationUtils.java    From Viewer with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
private static List<Camera.Area> buildMiddleArea(int areaPer1000) {
    return Collections.singletonList(
            new Camera.Area(new Rect(-areaPer1000, -areaPer1000, areaPer1000, areaPer1000), 1));
}
 
Example 19
Source File: CameraSettings.java    From Camera2 with Apache License 2.0 3 votes vote down vote up
/**
 * @param areas The areas for autoexposure. The coordinate system has domain
 *              and range [-1000,1000], measured relative to the visible
 *              preview image, with orientation matching that of the sensor.
 *              This means the coordinates must be transformed to account
 *              for the devices rotation---but not the zoom level---before
 *              being passed into this method.
 */
public void setMeteringAreas(List<Camera.Area> areas) {
    mMeteringAreas.clear();
    if (areas != null) {
        mMeteringAreas.addAll(areas);
    }
}
 
Example 20
Source File: ParameterUtils.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Convert the normalized camera area from [-1000, 1000] coordinate space
 * into the active array-based coordinate space.
 *
 * <p>Values out of range are clipped to be within the resulting (reported) crop
 * region. It is possible to have values larger than the preview crop.</p>
 *
 * <p>Weights out of range of [0, 1000] are clipped to be within the range.</p>
 *
 * @param activeArraySize active array size of the sensor (e.g. max jpeg size)
 * @param zoomData the calculated zoom data corresponding to this request
 * @param area the normalized camera area
 *
 * @return the weighed rectangle in active array coordinate space, with the weight
 */
public static WeightedRectangle convertCameraAreaToActiveArrayRectangle(
        Rect activeArray, ZoomData zoomData, Camera.Area area) {
    return convertCameraAreaToActiveArrayRectangle(activeArray, zoomData, area,
            /*usePreviewCrop*/true);
}