Dimensions
Leave feedback
On this page
Inheritance: java.lang.Object
public class Dimensions
Represents the linear dimensions (width and height) of one raster rectangular image in arbitrary unit. Immutable struct.
| Constructor | Description |
|---|---|
| Dimensions(int width, int height) | Creates a new instance from specified width and height |
| Method | Description |
|---|---|
| getWidth() | Returns width of the image |
| getHeight() | Returns height of the image |
| isSquare() | Determines whether specified ‘Dimensions’ represents square, i.e. |
| getArea() | Returns an area (Width x Height) |
| isEmpty() | Determines whether this “Dimensions” instance is empty and default, i.e. |
| getAspectRatio() | Aspect ratio of this dimensions as width/height |
| proportionallyResizeForNewWidth(int targetWidth) | Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified width |
| proportionallyResizeForNewHeight(int targetHeight) | Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified height |
| equals(Dimensions other) | Determines whether this instance is equal with specified “Dimensions” instance |
| equals(Object obj) | Determines whether this instance is equal with specified uncasted object, which presumably is another “Dimensions” instance |
| hashCode() | Returns a hashcode for this instance, which cannot be changed during its lifetime |
| op_Equality(Dimensions first, Dimensions second) | Checks whether two “Dimensions” values are equal, i.e. |
| op_Inequality(Dimensions first, Dimensions second) | Checks whether two “Dimensions” values are not equal, i.e. |
| toString() | Returns a string representation of this “Dimensions” |
| deepClone() | Returns a full copy of this instance |
| getEmpty() | Returns an empty Dimensions instance |
public Dimensions(int width, int height)
Creates a new instance from specified width and height
Parameters:
| Parameter | Type | Description |
|---|---|---|
| width | int | Width of image |
| height | int | Height of image |
public final int getWidth()
Returns width of the image
Returns: int
public final int getHeight()
Returns height of the image
Returns: int
public final boolean isSquare()
Determines whether specified ‘Dimensions’ represents square, i.e. if width is equal to height
Returns: boolean
public final long getArea()
Returns an area (Width x Height)
Returns: long
public final boolean isEmpty()
Determines whether this “Dimensions” instance is empty and default, i.e. it doesn’t store correct width and height
Returns: boolean
public final Ratio getAspectRatio()
Aspect ratio of this dimensions as width/height
Returns: Ratio
public final Dimensions proportionallyResizeForNewWidth(int targetWidth)
Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified width
Parameters:
| Parameter | Type | Description |
|---|---|---|
| targetWidth | int | New target width, that will be present in resultant Dimension |
Returns: Dimensions - New “Dimensions” instance with specified target width and proportionally resized height
public final Dimensions proportionallyResizeForNewHeight(int targetHeight)
Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified height
Parameters:
| Parameter | Type | Description |
|---|---|---|
| targetHeight | int | New target height, that will be present in resultant Dimension |
Returns: Dimensions - New “Dimensions” instance with specified target height and proportionally resized width
public final boolean equals(Dimensions other)
Determines whether this instance is equal with specified “Dimensions” instance
Parameters:
| Parameter | Type | Description |
|---|---|---|
| other | Dimensions | Other “Dimensions” instance to check on equality |
Returns: boolean - True if are equal, false if are not equal
public boolean equals(Object obj)
Determines whether this instance is equal with specified uncasted object, which presumably is another “Dimensions” instance
Parameters:
| Parameter | Type | Description |
|---|---|---|
| obj | java.lang.Object | Other object, that is presumably of “Dimensions” type, that should be checked on equality with this |
Returns: boolean - True if are equal, false if are not equal
public int hashCode()
Returns a hashcode for this instance, which cannot be changed during its lifetime
Returns: int - Immutable (for this instance) hash-code as signed 4-byte integer
public static boolean op_Equality(Dimensions first, Dimensions second)
Checks whether two “Dimensions” values are equal, i.e. they have equal width and height, or both are empty
Parameters:
| Parameter | Type | Description |
|---|---|---|
| first | Dimensions | First instance to check |
| second | Dimensions | Second instance to check |
Returns: boolean - True if are equal, false if are not equal
public static boolean op_Inequality(Dimensions first, Dimensions second)
Checks whether two “Dimensions” values are not equal, i.e. their corresponding width and/or height are different
Parameters:
| Parameter | Type | Description |
|---|---|---|
| first | Dimensions | First instance to check |
| second | Dimensions | Second instance to check |
Returns: boolean - True if are unequal, false if are equal
public String toString()
Returns a string representation of this “Dimensions”
W640×H480
Returns: java.lang.String - String instance, that contains a width and height in W:(width)×H:(height) format
public final Dimensions deepClone()
Returns a full copy of this instance
Returns: Dimensions - New instance, that is a full and deep copy of this one
public static Dimensions getEmpty()
Returns an empty Dimensions instance
Returns: Dimensions
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.