MeteringRectanglepublic final class MeteringRectangle extends Object An immutable class to represent a rectangle {@code (x, y, width, height)} with an additional
weight component.
The rectangle is defined to be inclusive of the specified coordinates.
When used with a {@link CaptureRequest}, the coordinate system is based on the active pixel
array, with {@code (0,0)} being the top-left pixel in the
{@link CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE active pixel array}, and
{@code (android.sensor.info.activeArraySize.width - 1,
android.sensor.info.activeArraySize.height - 1)} being the bottom-right pixel in the active pixel
array.
The weight must range from {@value #METERING_WEIGHT_MIN} to {@value #METERING_WEIGHT_MAX}
inclusively, and represents a weight for every pixel in the area. This means that a large
metering area with the same weight as a smaller area will have more effect in the metering
result. Metering areas can partially overlap and the camera device will add the weights in the
overlap rectangle.
If all rectangles have 0 weight, then no specific metering area needs to be used by the camera
device. If the metering rectangle is outside the used android.scaler.cropRegion returned in
capture result metadata, the camera device will ignore the sections outside the rectangle and
output the used sections in the result metadata.
|
Fields Summary |
---|
public static final int | METERING_WEIGHT_MINThe minimum value of valid metering weight. | public static final int | METERING_WEIGHT_MAXThe maximum value of valid metering weight. | public static final int | METERING_WEIGHT_DONT_CAREWeights set to this value will cause the camera device to ignore this rectangle.
If all metering rectangles are weighed with 0, the camera device will choose its own metering
rectangles. | private final int | mX | private final int | mY | private final int | mWidth | private final int | mHeight | private final int | mWeight |
Constructors Summary |
---|
public MeteringRectangle(int x, int y, int width, int height, int meteringWeight)Create a new metering rectangle.
mX = checkArgumentNonnegative(x, "x must be nonnegative");
mY = checkArgumentNonnegative(y, "y must be nonnegative");
mWidth = checkArgumentNonnegative(width, "width must be nonnegative");
mHeight = checkArgumentNonnegative(height, "height must be nonnegative");
mWeight = checkArgumentInRange(
meteringWeight, METERING_WEIGHT_MIN, METERING_WEIGHT_MAX, "meteringWeight");
| public MeteringRectangle(android.graphics.Point xy, android.util.Size dimensions, int meteringWeight)Create a new metering rectangle.
The point {@code xy}'s data is copied; the reference is not retained.
checkNotNull(xy, "xy must not be null");
checkNotNull(dimensions, "dimensions must not be null");
mX = checkArgumentNonnegative(xy.x, "x must be nonnegative");
mY = checkArgumentNonnegative(xy.y, "y must be nonnegative");
mWidth = checkArgumentNonnegative(dimensions.getWidth(), "width must be nonnegative");
mHeight = checkArgumentNonnegative(dimensions.getHeight(), "height must be nonnegative");
mWeight = checkArgumentNonnegative(meteringWeight, "meteringWeight must be nonnegative");
| public MeteringRectangle(android.graphics.Rect rect, int meteringWeight)Create a new metering rectangle.
The rectangle data is copied; the reference is not retained.
checkNotNull(rect, "rect must not be null");
mX = checkArgumentNonnegative(rect.left, "rect.left must be nonnegative");
mY = checkArgumentNonnegative(rect.top, "rect.top must be nonnegative");
mWidth = checkArgumentNonnegative(rect.width(), "rect.width must be nonnegative");
mHeight = checkArgumentNonnegative(rect.height(), "rect.height must be nonnegative");
mWeight = checkArgumentNonnegative(meteringWeight, "meteringWeight must be nonnegative");
|
Methods Summary |
---|
public boolean | equals(java.lang.Object other){@inheritDoc}
return other instanceof MeteringRectangle && equals((MeteringRectangle)other);
| public boolean | equals(android.hardware.camera2.params.MeteringRectangle other)Compare two metering rectangles to see if they are equal.
Two weighted rectangles are only considered equal if each of their components
(x, y, width, height, weight) is respectively equal.
if (other == null) {
return false;
}
return (mX == other.mX
&& mY == other.mY
&& mWidth == other.mWidth
&& mHeight == other.mHeight
&& mWeight == other.mWeight);
| public int | getHeight()Return the height of the rectangle.
return mHeight;
| public int | getMeteringWeight()Return the metering weight of the rectangle.
return mWeight;
| public android.graphics.Rect | getRect()Convenience method to create a {@link Rect} from this metering rectangle.
This strips away the weight from the rectangle.
return new Rect(mX, mY, mX + mWidth, mY + mHeight);
| public android.util.Size | getSize()Convenience method to create the size from this metering rectangle.
This strips away the X,Y,weight from the rectangle.
return new Size(mWidth, mHeight);
| public android.graphics.Point | getUpperLeftPoint()Convenience method to create the upper-left (X,Y) coordinate as a {@link Point}.
return new Point(mX, mY);
| public int | getWidth()Return the width of the rectangle.
return mWidth;
| public int | getX()Return the X coordinate of the left side of the rectangle.
return mX;
| public int | getY()Return the Y coordinate of the upper side of the rectangle.
return mY;
| public int | hashCode(){@inheritDoc}
return HashCodeHelpers.hashCode(mX, mY, mWidth, mHeight, mWeight);
| public java.lang.String | toString()Return the metering rectangle as a string representation
{@code "(x:%d, y:%d, w:%d, h:%d, wt:%d)"} where each {@code %d} respectively represents
the x, y, width, height, and weight points.
return String.format("(x:%d, y:%d, w:%d, h:%d, wt:%d)", mX, mY, mWidth, mHeight, mWeight);
|
|