Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#constants) \| [Ctors](https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#pubctors) \| [Methods](https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#inhmethods)

# MeteringRectangle

*** ** * ** ***


`
public

final

class
MeteringRectangle
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.camera2.params.MeteringRectangle |

<br />

*** ** * ** ***

An immutable class to represent a rectangle `(x, y, width, height)` with an additional
weight component.


The rectangle is defined to be inclusive of the specified coordinates.


When used with a `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest`, the coordinate system is based on the active pixel
array, with `(0,0)` being the top-left pixel in the
`https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE`, and
`(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 `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#METERING_WEIGHT_MIN` to `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#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.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#METERING_WEIGHT_DONT_CARE` Weights set to this value will cause the camera device to ignore this rectangle. |
| `int` | `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#METERING_WEIGHT_MAX` The maximum value of valid metering weight. |
| `int` | `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#METERING_WEIGHT_MIN` The minimum value of valid metering weight. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#MeteringRectangle(android.graphics.Point,%20android.util.Size,%20int)(https://developer.android.com/reference/android/graphics/Point xy, https://developer.android.com/reference/android/util/Size dimensions, int meteringWeight) ` Create a new metering rectangle. |
| ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#MeteringRectangle(android.graphics.Rect,%20int)(https://developer.android.com/reference/android/graphics/Rect rect, int meteringWeight) ` Create a new metering rectangle. |
| ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#MeteringRectangle(int,%20int,%20int,%20int,%20int)(int x, int y, int width, int height, int meteringWeight) ` Create a new metering rectangle. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object other) ` Indicates whether some other object is "equal to" this one. |
| ` boolean` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#equals(android.hardware.camera2.params.MeteringRectangle)(https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle other) ` Compare two metering rectangles to see if they are equal. |
| ` int` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getHeight()() ` Return the height of the rectangle. |
| ` int` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getMeteringWeight()() ` Return the metering weight of the rectangle. |
| ` https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getRect()() ` Convenience method to create a `https://developer.android.com/reference/android/graphics/Rect` from this metering rectangle. |
| ` https://developer.android.com/reference/android/util/Size` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getSize()() ` Convenience method to create the size from this metering rectangle. |
| ` https://developer.android.com/reference/android/graphics/Point` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getUpperLeftPoint()() ` Convenience method to create the upper-left (X,Y) coordinate as a `https://developer.android.com/reference/android/graphics/Point`. |
| ` int` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getWidth()() ` Return the width of the rectangle. |
| ` int` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getX()() ` Return the X coordinate of the left side of the rectangle. |
| ` int` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#getY()() ` Return the Y coordinate of the upper side of the rectangle. |
| ` int` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#hashCode()() ` Returns a hash code value for the object. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#toString()() ` Return the metering rectangle as a string representation `"(x:%d, y:%d, w:%d, h:%d, wt:%d)"` where each `%d` respectively represents the x, y, width, height, and weight points. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### METERING_WEIGHT_DONT_CARE

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int METERING_WEIGHT_DONT_CARE
```

Weights 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.

<br />

Constant Value:

0
(0x00000000)


### METERING_WEIGHT_MAX

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int METERING_WEIGHT_MAX
```

The maximum value of valid metering weight.

<br />

Constant Value:

1000
(0x000003e8)


### METERING_WEIGHT_MIN

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int METERING_WEIGHT_MIN
```

The minimum value of valid metering weight.

<br />

Constant Value:

0
(0x00000000)


## Public constructors

### MeteringRectangle

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeteringRectangle (Point xy, 
                Size dimensions, 
                int meteringWeight)
```

Create a new metering rectangle.

The point `xy`'s data is copied; the reference is not retained.

<br />

<br />

| Parameters ||
|---|---|
| `xy` | `Point`: a non-`null` `https://developer.android.com/reference/android/graphics/Point` with both x,y \>= 0 <br /> |
| `dimensions` | `Size`: a non-`null` `https://developer.android.com/reference/android/util/Size` with width, height \>= 0 <br /> |
| `meteringWeight` | `int`: weight \>= 0 <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if any of the parameters were negative |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if any of the arguments were null |

### MeteringRectangle

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeteringRectangle (Rect rect, 
                int meteringWeight)
```

Create a new metering rectangle.

The rectangle data is copied; the reference is not retained.

<br />

<br />

| Parameters ||
|---|---|
| `rect` | `Rect`: a non-`null` rectangle with all x,y,w,h dimensions \>= 0 <br /> |
| `meteringWeight` | `int`: weight \>= 0 <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if any of the parameters were negative |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if any of the arguments were null |

### MeteringRectangle

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MeteringRectangle (int x, 
                int y, 
                int width, 
                int height, 
                int meteringWeight)
```

Create a new metering rectangle.

<br />

| Parameters ||
|---|---|
| `x` | `int`: coordinate \>= 0 <br /> |
| `y` | `int`: coordinate \>= 0 <br /> |
| `width` | `int`: width \>= 0 <br /> |
| `height` | `int`: height \>= 0 <br /> |
| `meteringWeight` | `int`: weight between `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#METERING_WEIGHT_MIN` and `https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle#METERING_WEIGHT_MAX` inclusively <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if any of the parameters were negative |

## Public methods

### equals

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object other)
```

Indicates whether some other object is "equal to" this one.


The `equals` method implements an equivalence relation
on non-null object references:

- It is *reflexive*: for any non-null reference value `x`, `x.equals(x)` should return `true`.
- It is *symmetric*: for any non-null reference values `x` and `y`, `x.equals(y)` should return `true` if and only if `y.equals(x)` returns `true`.
- It is *transitive*: for any non-null reference values `x`, `y`, and `z`, if `x.equals(y)` returns `true` and `y.equals(z)` returns `true`, then `x.equals(z)` should return `true`.
- It is *consistent*: for any non-null reference values `x` and `y`, multiple invocations of `x.equals(y)` consistently return `true` or consistently return `false`, provided no information used in `equals` comparisons on the objects is modified.
- For any non-null reference value `x`, `x.equals(null)` should return `false`.


An equivalence relation partitions the elements it operates on
into *equivalence classes*; all the members of an
equivalence class are equal to each other. Members of an
equivalence class are substitutable for each other, at least
for some purposes.

<br />

| Parameters ||
|---|---|
| `other` | `Object`: the reference object with which to compare. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this object is the same as the obj argument; `false` otherwise. <br /> |

### equals

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (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.

<br />

| Parameters ||
|---|---|
| `other` | `MeteringRectangle`: Another MeteringRectangle <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the metering rectangles are equal, `false` otherwise <br /> |

### getHeight

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getHeight ()
```

Return the height of the rectangle.

<br />

| Returns ||
|---|---|
| `int` | height \>= 0 <br /> |

### getMeteringWeight

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getMeteringWeight ()
```

Return the metering weight of the rectangle.

<br />

| Returns ||
|---|---|
| `int` | weight \>= 0 <br /> |

### getRect

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Rect getRect ()
```

Convenience method to create a `https://developer.android.com/reference/android/graphics/Rect` from this metering rectangle.

This strips away the weight from the rectangle.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Rect` | a new `https://developer.android.com/reference/android/graphics/Rect` with non-negative x1, y1, x2, y2 <br /> |

### getSize

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Size getSize ()
```

Convenience method to create the size from this metering rectangle.

This strips away the X,Y,weight from the rectangle.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/util/Size` | a new `https://developer.android.com/reference/android/util/Size` with non-negative width and height <br /> |

### getUpperLeftPoint

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Point getUpperLeftPoint ()
```

Convenience method to create the upper-left (X,Y) coordinate as a `https://developer.android.com/reference/android/graphics/Point`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Point` | a new `(x,y)` `https://developer.android.com/reference/android/graphics/Point` with both x,y \>= 0 <br /> |

### getWidth

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getWidth ()
```

Return the width of the rectangle.

<br />

| Returns ||
|---|---|
| `int` | width \>= 0 <br /> |

### getX

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getX ()
```

Return the X coordinate of the left side of the rectangle.

<br />

| Returns ||
|---|---|
| `int` | x coordinate \>= 0 <br /> |

### getY

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getY ()
```

Return the Y coordinate of the upper side of the rectangle.

<br />

| Returns ||
|---|---|
| `int` | y coordinate \>= 0 <br /> |

### hashCode

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
`https://developer.android.com/reference/java/util/HashMap`.


The general contract of `hashCode` is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the `hashCode` method must consistently return the same integer, provided no information used in `equals` comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce the same integer result.
- It is *not* required that if two objects are unequal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

| Returns ||
|---|---|
| `int` | a hash code value for this object. <br /> |

### toString

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Return the metering rectangle as a string representation
`"(x:%d, y:%d, w:%d, h:%d, wt:%d)"` where each `%d` respectively represents
the x, y, width, height, and weight points.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | string representation of the metering rectangle <br /> |