public class AwtImage
extends java.lang.Object
Constructor and Description |
---|
AwtImage(java.awt.image.BufferedImage awt) |
Modifier and Type | Method and Description |
---|---|
int[][] |
argb()
Returns the ARGB components for all pixels in this image
|
int[] |
argb(int x,
int y)
Returns the ARGB components for the pixel at the given coordinates
|
int[] |
argbints()
Returns the ARGB components for all pixels in this image as packed ints.
|
RGBColor |
average()
Returns the average colour of all pixels in this image
|
java.awt.image.BufferedImage |
awt()
Returns the [BufferedImage] that this Image is wrapping.
|
Pixel |
bottomLeftPixel() |
Pixel |
bottomRightPixel() |
byte[] |
bytes(ImageWriter writer) |
java.awt.Point |
center()
The centre coordinates for the image.
|
int |
centreX() |
int |
centreY() |
Pixel[] |
col(int x) |
RGBColor |
color(int x,
int y)
Returns the color at the given coordinates.
|
RGBColor[] |
colors()
Returns the colors of this image represented as an array of RGBColor.
|
java.util.Set<RGBColor> |
colours()
Returns a set of the distinct colours used in this image.
|
boolean |
contains(java.awt.Color color)
Returns true if a pixel with the given color exists
|
int |
count()
Returns the number of pixels in the image.
|
long |
count(java.awt.Color color)
Counts the number of pixels with the given colour.
|
long |
count(java.util.function.Predicate<Pixel> p)
Counts the number of pixels that are true for the given predicate
|
Dimension |
dimensions() |
AwtImage |
empty()
Returns a new AWTImage with the same dimensions and same AWT type.
|
boolean |
equals(java.lang.Object other) |
boolean |
exists(java.util.function.Predicate<Pixel> p)
Returns true if the predicate is true for at least one pixel on the image.
|
protected java.awt.image.BufferedImage |
fastScaleAwt(int targetWidth,
int targetHeight)
Returns a new AWT BufferedImage scaled using nearest-neighbour.
|
protected java.awt.image.BufferedImage |
fastScaleScrimage(int targetWidth,
int targetHeight) |
boolean |
forAll(java.util.function.Predicate<Pixel> predicate)
Returns true if the given predicate holds for all pixels in the image.
|
void |
forEach(java.util.function.Consumer<Pixel> fn)
Executes the given side effecting function on each pixel.
|
WriteContext |
forWriter(ImageWriter writer) |
int |
getType()
Returns the AWT type of this image.
|
boolean |
hasAlpha()
Returns true if this image supports transparency/alpha in its underlying data model.
|
int |
hashCode() |
boolean |
hasTransparency()
Returns true if this image supports transparency/alpha in its underlying data model.
|
boolean |
isFilled(java.awt.Color color)
Returns true if all the pixels on this image are a single color.
|
java.util.Iterator<Pixel> |
iterator()
Returns the pixels of the image as an iterator.
|
int |
offset(int x,
int y) |
java.io.File |
output(ImageWriter writer,
java.io.File file) |
java.nio.file.Path |
output(ImageWriter writer,
java.nio.file.Path path) |
java.nio.file.Path |
output(ImageWriter writer,
java.lang.String path) |
Pixel[] |
patch(int x,
int y,
int patchWidth,
int patchHeight) |
Pixel[][] |
patches(int patchWidth,
int patchHeight)
Returns all the patches of a given size in the image, assuming pixel
alignment (no subpixel extraction).
|
Pixel |
pixel(int x,
int y)
Returns the pixel at the given coordinates.
|
Pixel |
pixel(java.awt.Point p)
Returns the pixel at the given coordinate.
|
Pixel[] |
pixels()
Returns the pixels of this image represented as an array of Pixels.
|
Pixel[] |
pixels(int x,
int y,
int w,
int h)
Returns a rectangular region within the given boundaries as a single
dimensional array of Pixels.
|
java.awt.Point[] |
points()
Returns an array of every point in the image, useful if you want to be able to
iterate over all the coordinates.
|
int |
radius()
The radius of the image defined as the centre to the corners.
|
double |
ratio() |
int[][] |
rgb() |
int[] |
rgb(int x,
int y) |
protected java.awt.image.BufferedImage |
rotateByRadians(Radians angle)
Returns a new AWT Image rotated with the given angle (in radians)
|
Pixel[] |
row(int y) |
protected java.awt.image.BufferedImage |
scale(int targetWidth,
int targetHeight,
Scale scale) |
java.io.ByteArrayInputStream |
stream(ImageWriter writer)
Deprecated.
pointless method that simply wraps bytes()
|
int |
subpixel(double x,
double y)
Uses linear interpolation to get a sub-pixel.
|
ImmutableImage |
toImmutableImage() |
java.awt.image.BufferedImage |
toNewBufferedImage(int type)
Returns a new AWT BufferedImage from this image.
|
Pixel |
topLeftPixel()
Programatically returns the origin point of top left.
|
Pixel |
topRightPixel() |
java.lang.String |
toString() |
public ImmutableImage toImmutableImage()
public java.awt.image.BufferedImage awt()
public java.awt.Point center()
public int centreX()
public int centreY()
public int radius()
public Dimension dimensions()
public double ratio()
public int getType()
public RGBColor[] colors()
public Pixel[] pixels()
public java.util.Iterator<Pixel> iterator()
The iterator is the most efficient way to lazily iterator over the pixels as the pixels will only be fetched from the raster as needed.
public Pixel pixel(int x, int y)
x
- the x coordinate of the pixel to graby
- the y coordinate of the pixel to grabpublic Pixel pixel(java.awt.Point p)
p
- the pixel as an integer tuplepublic java.awt.Point[] points()
If you want the actual pixel values of every point then use pixels().
public int count()
public void forEach(java.util.function.Consumer<Pixel> fn)
fn
- a function that accepts a pixelpublic Pixel[] row(int y)
public Pixel[] col(int x)
public boolean contains(java.awt.Color color)
color
- the pixel colour to look for.public boolean exists(java.util.function.Predicate<Pixel> p)
p
- a predicatepublic RGBColor color(int x, int y)
public int[] argb(int x, int y)
x
- the x coordinate of the pixel component to graby
- the y coordinate of the pixel component to grabpublic int[][] argb()
public int[] argbints()
public int[] rgb(int x, int y)
public int[][] rgb()
public Pixel[] pixels(int x, int y, int w, int h)
Eg, pixels(10, 10, 30, 20) would result in an array of size 600 with the first row of the region in indexes 0,..,29, second row 30,..,59 etc.
x
- the start x coordinatey
- the start y coordinatew
- the width of the regionh
- the height of the regionpublic Pixel[] patch(int x, int y, int patchWidth, int patchHeight)
public java.lang.String toString()
toString
in class java.lang.Object
public int subpixel(double x, double y)
Legal values for `x` and `y` are in [0, width) and [0, height), respectively.
public Pixel[][] patches(int patchWidth, int patchHeight)
The patches are returned as an array of of pixel matrices arrays.
public int offset(int x, int y)
public java.util.Set<RGBColor> colours()
public long count(java.awt.Color color)
color
- the colour to detect.public long count(java.util.function.Predicate<Pixel> p)
p
- a predicatepublic java.awt.image.BufferedImage toNewBufferedImage(int type)
type
- the type of buffered image to create, if not specified then defaults to the current image typepublic AwtImage empty()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
protected java.awt.image.BufferedImage scale(int targetWidth, int targetHeight, Scale scale)
protected java.awt.image.BufferedImage fastScaleScrimage(int targetWidth, int targetHeight)
protected java.awt.image.BufferedImage fastScaleAwt(int targetWidth, int targetHeight)
protected java.awt.image.BufferedImage rotateByRadians(Radians angle)
public boolean forAll(java.util.function.Predicate<Pixel> predicate)
public Pixel topLeftPixel()
public Pixel bottomLeftPixel()
public Pixel topRightPixel()
public Pixel bottomRightPixel()
public boolean hasAlpha()
public boolean hasTransparency()
public RGBColor average()
public boolean isFilled(java.awt.Color color)
color
- the color to test pixels againstpublic java.nio.file.Path output(ImageWriter writer, java.lang.String path) throws java.io.IOException
java.io.IOException
public java.io.File output(ImageWriter writer, java.io.File file) throws java.io.IOException
java.io.IOException
public java.nio.file.Path output(ImageWriter writer, java.nio.file.Path path) throws java.io.IOException
java.io.IOException
public byte[] bytes(ImageWriter writer) throws java.io.IOException
java.io.IOException
public WriteContext forWriter(ImageWriter writer)
@Deprecated public java.io.ByteArrayInputStream stream(ImageWriter writer) throws java.io.IOException
java.io.IOException