public class ImmutableImage extends MutableImage
An Image represents an abstraction that allow operations such as resize, scale, rotate, flip, trim, pad, cover, fit.
All operations on an ImmutableImage are read only or return a cloned instance of this image. For operations that can be performed without a copying step, see MutableImage.
Modifier and Type | Field and Description |
---|---|
static int |
CANONICAL_DATA_TYPE
Deprecated.
|
static int |
DEFAULT_DATA_TYPE |
static int |
UNDERLYING_DATA_TYPE |
Modifier and Type | Method and Description |
---|---|
ImmutableImage |
associateMetadata(ImageMetadata metadata)
Returns this image, with metadata attached.
|
ImmutableImage |
autocrop() |
ImmutableImage |
autocrop(java.awt.Color color) |
ImmutableImage |
autocrop(java.awt.Color color,
int colorTolerance)
Crops an image by removing cols and rows that are composed only of a single
given color.
|
ImmutableImage |
blank()
Creates an empty ImmutableImage of the same concrete type as this image and with the same dimensions.
|
ImmutableImage |
bound(int w,
int h)
Convenience method for bound(w, h, ScaleMethod.Bicubic)
|
ImmutableImage |
bound(int w,
int h,
ScaleMethod scaleMethod)
Returns an image that is no larger than the given width and height keeping the same aspect ratio.
|
ImmutableImage |
brightness(double factor)
Returns a new Image with the brightness adjusted.
|
ImmutableImage |
composite(Composite composite,
ImmutableImage applicative)
Apply the given image with this image using the given composite.
|
ImmutableImage |
contrast(double factor)
Returns a new Image with the contrast adjusted.
|
ImmutableImage |
copy()
Creates a new image with the same data as this image.
|
ImmutableImage |
copy(int type)
Returns a copy of this image with the underlying image type set to the given value.
|
ImmutableImage |
cover(int targetWidth,
int targetHeight)
Convenience method for cover(targetWidth, targetHeight, ScaleMethod.Bicubic, Position.Center)
|
ImmutableImage |
cover(int targetWidth,
int targetHeight,
Position position)
Convenience method for cover(targetWidth, targetHeight, ScaleMethod.Bicubic, position)
|
ImmutableImage |
cover(int targetWidth,
int targetHeight,
ScaleMethod scaleMethod,
Position position)
Returns an image with the given dimensions where this image has been scaled to
completely cover the new dimensions whilst retaining the original aspect ratio.
|
static ImmutableImage |
create(int width,
int height)
Create a new ImmutableImage that is the given width and height with no initialization.
|
static ImmutableImage |
create(int width,
int height,
int type)
Create a new ImmutableImage that is the given width and height and type with no initialization.
|
static ImmutableImage |
create(int w,
int h,
Pixel[] pixels)
Create a new Image from an array of pixels.
|
static ImmutableImage |
create(int w,
int h,
Pixel[] pixels,
int type)
Create a new Image from an array of pixels with the given type.
|
ImmutableImage |
fill(java.awt.Color color)
Creates a new Image with the same dimensions of this image and with
all the pixels initialized to the given color.
|
ImmutableImage |
fill(Painter painter)
Creates a new Image with the same dimensions of this image and with
all the pixels initialized using the given painter.
|
static ImmutableImage |
filled(int width,
int height,
java.awt.Color color)
Return a new ImmutableImage with the given width and height, with all pixels set to the supplied colour.
|
static ImmutableImage |
filled(int width,
int height,
java.awt.Color color,
int type)
Return a new ImmutableImage with the given width and height and type, with all pixels
set to the supplied colour.
|
ImmutableImage |
filter(Filter... filters)
Apply a sequence of filters in sequence.
|
ImmutableImage |
filter(Filter filter)
Creates a copy of this image with the given filter applied.
|
ImmutableImage |
fit(int canvasWidth,
int canvasHeight)
Convenience method for:
fit(canvasWidth, canvasHeight, Colors.Transparent.toAWT(), ScaleMethod.Bicubic, Position.Center)
|
ImmutableImage |
fit(int canvasWidth,
int canvasHeight,
java.awt.Color color) |
ImmutableImage |
fit(int canvasWidth,
int canvasHeight,
java.awt.Color color,
Position position) |
ImmutableImage |
fit(int canvasWidth,
int canvasHeight,
java.awt.Color color,
ScaleMethod scaleMethod,
Position position)
Returns a copy of this image with the given dimensions
where the original image has been scaled to fit completely
inside the new dimensions whilst retaining the original aspect ratio.
|
ImmutableImage |
fit(int canvasWidth,
int canvasHeight,
ScaleMethod scaleMethod) |
ImmutableImage |
flipX()
Flips this image horizontally.
|
ImmutableImage |
flipY()
Flips this image vertically.
|
WriteContext |
forWriter(ImageWriter writer) |
static ImmutableImage |
fromAwt(java.awt.image.BufferedImage awt)
Create a new [ImmutableImage] from a source AWT Image.
|
static ImmutableImage |
fromAwt(java.awt.image.BufferedImage awt,
int type)
Create a new [ImmutableImage] from a source AWT Image.
|
static ImmutableImage |
fromFile(java.io.File file)
Deprecated.
use ImmutableImage.loader().fromFile(file);
|
static ImmutableImage |
fromPath(java.nio.file.Path path)
Deprecated.
use ImmutableImage.loader().fromPath(path);
|
static ImmutableImage |
fromResource(java.lang.String path)
Deprecated.
use ImmutableImage.loader().fromResource(file);
|
static ImmutableImage |
fromResource(java.lang.String path,
int type)
Deprecated.
use ImmutableImage.loader().fromResource(file);
|
static ImmutableImage |
fromStream(java.io.InputStream in)
Deprecated.
use ImmutableImage.loader().fromFile(file);
|
static ImmutableImage |
fromStream(java.io.InputStream in,
int type)
Deprecated.
use ImmutableImage.loader().fromFile(file);
|
ImageMetadata |
getMetadata() |
static ImmutableImageLoader |
loader() |
ImmutableImage |
map(java.util.function.Function<Pixel,java.awt.Color> mapper)
Maps the pixels of this image into another image by applying the given function to each pixel.
|
ImmutableImage |
max(int maxW,
int maxH)
Convenience method for max(maxW, maxH, ScaleMethod.Bicubic)
|
ImmutableImage |
max(int maxW,
int maxH,
ScaleMethod scaleMethod)
Returns a new image that is scaled to fit the specified bounds while retaining the same aspect ratio
as the original image.
|
ImmutableImage |
op(java.awt.image.BufferedImageOp op) |
ImmutableImage |
overlay(AwtImage overlayImage)
Returns a new image that is the result of overlaying the given image over this image.
|
ImmutableImage |
overlay(AwtImage overlayImage,
int x,
int y) |
ImmutableImage |
overlay(ImmutableImage image,
Position position) |
ImmutableImage |
pad(int size,
java.awt.Color color)
Creates a new image which is the result of this image
padded with the given number of pixels on each edge.
|
ImmutableImage |
padBottom(int k,
java.awt.Color color)
Creates a new Image by adding k amount of rows of pixels to the bottom.
|
ImmutableImage |
padLeft(int k)
Creates a new Image by adding k columns of pixels to the left.
|
ImmutableImage |
padLeft(int k,
java.awt.Color color)
Creates a new Image by adding k columns of pixels to the left.
|
ImmutableImage |
padRight(int k)
Creates a new Image by adding k columns of pixels to the right.
|
ImmutableImage |
padRight(int k,
java.awt.Color color)
Creates a new Image by adding k columns of pixels to the right.
|
ImmutableImage |
padTo(int targetWidth,
int targetHeight) |
ImmutableImage |
padTo(int targetWidth,
int targetHeight,
java.awt.Color color)
Creates a new ImmutableImage which is the result of this image padded to the canvas size specified.
|
ImmutableImage |
padTop(int k,
java.awt.Color color)
Creates a new Image by adding k amount of rows of pixels to the top.
|
ImmutableImage |
padWith(int left,
int top,
int right,
int bottom) |
ImmutableImage |
padWith(int left,
int top,
int right,
int bottom,
java.awt.Color color)
Creates a new ImmutableImage by adding the given number of columns/rows on left, top, right and bottom.
|
static ImmutableImage |
parse(byte[] bytes)
Deprecated.
use ImmutableImage.loader().fromBytes(file);
|
static ImmutableImage |
parse(byte[] bytes,
int type)
Deprecated.
use ImmutableImage.loader().fromBytes(file);
|
RGBColor[] |
quantize(int colours)
Returns the most n used colours in this image.
|
ImmutableImage |
removeTransparency(java.awt.Color color)
Returns a new ImmutableImage with transparency replaced with the given color.
|
ImmutableImage |
resize(double scaleFactor) |
ImmutableImage |
resize(double scaleFactor,
java.awt.Color background) |
ImmutableImage |
resize(double scaleFactor,
Position position) |
ImmutableImage |
resize(double scaleFactor,
Position position,
java.awt.Color background)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
resizeTo(int targetWidth,
int targetHeight) |
ImmutableImage |
resizeTo(int targetWidth,
int targetHeight,
java.awt.Color color) |
ImmutableImage |
resizeTo(int targetWidth,
int targetHeight,
Position position) |
ImmutableImage |
resizeTo(int targetWidth,
int targetHeight,
Position position,
java.awt.Color background)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
resizeToHeight(int targetHeight)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
resizeToHeight(int targetHeight,
Position position,
java.awt.Color background)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
resizeToRatio(double targetRatio) |
ImmutableImage |
resizeToRatio(double targetRatio,
Position position,
java.awt.Color background)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
resizeToWidth(int targetWidth)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
resizeToWidth(int targetWidth,
Position position,
java.awt.Color background)
Resize will resize the canvas, it will not scale the image.
|
ImmutableImage |
rotate(Degrees degrees) |
ImmutableImage |
rotate(Radians radians) |
ImmutableImage |
rotateLeft()
Returns a copy of this image rotated 90 degrees anti-clockwise (counter clockwise to US English speakers).
|
ImmutableImage |
rotateRight()
Returns a copy of this image rotated 90 degrees clockwise.
|
ImmutableImage |
scale(double scaleFactor) |
ImmutableImage |
scale(double scaleFactor,
ScaleMethod scaleMethod)
Scale will resize the canvas and the image.
|
ImmutableImage |
scaleHeightToRatio(double ratio) |
ImmutableImage |
scaleHeightToRatio(double ratio,
ScaleMethod scaleMethod) |
ImmutableImage |
scaleTo(int targetWidth,
int targetHeight)
Convenience method for scaleTo(targetWidth, targetHeight, ScaleMethod.Bicubic);
|
ImmutableImage |
scaleTo(int targetWidth,
int targetHeight,
ScaleMethod scaleMethod)
Scale will resize both the canvas and the image.
|
ImmutableImage |
scaleToHeight(int targetHeight)
Convenience method for scaleToHeight(targetHeight, ScaleMethod.Bicubic)
|
ImmutableImage |
scaleToHeight(int targetHeight,
ScaleMethod scaleMethod)
Convenience method for scaleToHeight(targetHeight, scaleMethod, true)
|
ImmutableImage |
scaleToHeight(int targetHeight,
ScaleMethod scaleMethod,
boolean keepAspectRatio)
Scale will resize the canvas and scale the image to match.
|
ImmutableImage |
scaleToWidth(int targetWidth)
Convenience method for scaleToWidth(targetWith, scaleMethod)
|
ImmutableImage |
scaleToWidth(int targetWidth,
ScaleMethod scaleMethod)
Scale will resize the canvas and scale the image to match.
|
ImmutableImage |
scaleToWidth(int targetWidth,
ScaleMethod scaleMethod,
boolean keepAspectRatio) |
ImmutableImage |
subimage(int x,
int y,
int w,
int h)
Returns a new Image that is a subimage or region of the original image.
|
ImmutableImage |
subimage(java.awt.Rectangle rectangle) |
ImmutableImage |
subpixelSubimage(double x,
double y,
int subWidth,
int subHeight)
Extracts a subimage, but using subpixel interpolation.
|
ImmutableImage |
subpixelSubimageCenteredAtPoint(double x,
double y,
double xRadius,
double yRadius)
Extract a patch, centered at a subpixel point.
|
ImmutableImage |
takeBottom(int k)
Returns a new Image which is the source image, but only keeping a max of k rows from the bottom.
|
ImmutableImage |
takeLeft(int k)
Returns a new Image which is the source image, but only keeping a max of k columns from the left.
|
ImmutableImage |
takeRight(int k)
Returns a new Image which is the source image, but only keeping a max of k columns from the right.
|
ImmutableImage |
takeTop(int k)
Returns a new Image which is the source image, but only keeping a max of k rows from the top.
|
Canvas |
toCanvas()
Returns a Canvas that wraps this image.
|
ImmutableImage |
transform(Transform transform) |
ImmutableImage |
translate(int x,
int y)
Returns an image that is the result of translating the image while keeping the same
view window.
|
ImmutableImage |
translate(int x,
int y,
java.awt.Color bg)
Returns an image that is the result of translating the image while keeping the same
view window.
|
ImmutableImage |
trim(int amount)
Removes the given amount of pixels from each edge; like a crop operation.
|
ImmutableImage |
trim(int left,
int top,
int right,
int bottom)
Removes the given amount of pixels from each edge; like a crop operation.
|
ImmutableImage |
trimBottom(int k)
Removes the specified amount of rows of pixels from the bottom of the image.
|
ImmutableImage |
trimLeft(int k)
Removes the specified amount of columns of pixels from the left side of the image.
|
ImmutableImage |
trimRight(int k)
Removes the specified amount of columns of pixels from the right side of the image.
|
ImmutableImage |
trimTop(int k)
Removes the specified amount of rows of pixels from the top of the image.
|
ImmutableImage |
underlay(ImmutableImage underlayImage) |
ImmutableImage |
underlay(ImmutableImage underlayImage,
int x,
int y)
Returns a new Image that is the result of overlaying this image over the supplied image.
|
static ImmutableImage |
wrapAwt(java.awt.image.BufferedImage awt)
Creates a new [ImmutableImage] from an AWT image by wrapping that source image.
|
static ImmutableImage |
wrapAwt(java.awt.image.BufferedImage awt,
ImageMetadata metadata)
Creates a new [ImmutableImage] from an AWT image by wrapping that source image.
|
static ImmutableImage |
wrapAwt(java.awt.image.BufferedImage awt,
int type)
Creates a new [ImmutableImage] from an AWT image by wrapping that source image.
|
static ImmutableImage |
wrapPixels(int w,
int h,
Pixel[] pixels,
ImageMetadata metadata) |
ImmutableImage |
zoom(double factor) |
ImmutableImage |
zoom(double factor,
ScaleMethod method)
Returns a new image that is the result of scaling this image but without changing the canvas size.
|
contrastInPlace, fillInPlace, mapInPlace, overlayInPlace, replaceTransparencyInPlace, rescaleInPlace, setColor, setColor, setPixel
argb, argb, argbints, average, awt, bottomLeftPixel, bottomRightPixel, bytes, center, centreX, centreY, col, color, colors, colours, contains, count, count, count, dimensions, empty, equals, exists, fastScaleAwt, fastScaleScrimage, forAll, forEach, getType, hasAlpha, hashCode, hasTransparency, isFilled, iterator, offset, output, output, output, patch, patches, pixel, pixel, pixels, pixels, points, radius, ratio, rgb, rgb, rotateByRadians, row, scale, stream, subpixel, toImmutableImage, toNewBufferedImage, topLeftPixel, topRightPixel, toString
public static final int DEFAULT_DATA_TYPE
@Deprecated public static final int CANONICAL_DATA_TYPE
public static final int UNDERLYING_DATA_TYPE
public static ImmutableImageLoader loader()
public static ImmutableImage fromAwt(java.awt.image.BufferedImage awt)
awt
- the source AWT Imagepublic static ImmutableImage fromAwt(java.awt.image.BufferedImage awt, int type)
If the given type is greater than 0, then a copy will be made using that type for the image. If the param type is -1, then the source image type will be used, unless the source image has type 0, in which case BufferedImage.TYPE_INT_ARGB will be used.
awt
- the source AWT Imagepublic static ImmutableImage wrapAwt(java.awt.image.BufferedImage awt, ImageMetadata metadata)
awt
- the source AWT Imagemetadata
- the image metadatapublic static ImmutableImage wrapAwt(java.awt.image.BufferedImage awt)
awt
- the source AWT Imagepublic static ImmutableImage wrapAwt(java.awt.image.BufferedImage awt, int type)
If the given awt image does not have the same type as requested, then this will force the image to be copied using [fromAwt].
awt
- the source AWT Imagetype
- the AWT image type to use. If the image is not in this format already it will be coped.
specify UNDERLYING_DATA_TYPE if you want to use the originalpublic static ImmutableImage wrapPixels(int w, int h, Pixel[] pixels, ImageMetadata metadata)
@Deprecated public static ImmutableImage fromFile(java.io.File file) throws java.io.IOException
java.io.IOException
@Deprecated public static ImmutableImage fromPath(java.nio.file.Path path) throws java.io.IOException
java.io.IOException
public static ImmutableImage create(int width, int height)
width
- the width of the new imageheight
- the height of the new imagepublic static ImmutableImage create(int width, int height, int type)
width
- the width of the new imageheight
- the height of the new imagepublic static ImmutableImage filled(int width, int height, java.awt.Color color)
width
- the width of the new Imageheight
- the height of the new Imagecolor
- the color to set all pixels topublic static ImmutableImage filled(int width, int height, java.awt.Color color, int type)
width
- the width of the new Imageheight
- the height of the new Imagecolor
- the color to set all pixels to@Deprecated public static ImmutableImage fromStream(java.io.InputStream in) throws java.io.IOException
in
- the stream to read the bytes fromjava.io.IOException
@Deprecated public static ImmutableImage fromStream(java.io.InputStream in, int type) throws java.io.IOException
in
- the stream to read the bytes fromjava.io.IOException
@Deprecated public static ImmutableImage fromResource(java.lang.String path) throws java.io.IOException
java.io.IOException
@Deprecated public static ImmutableImage fromResource(java.lang.String path, int type) throws java.io.IOException
java.io.IOException
public static ImmutableImage create(int w, int h, Pixel[] pixels)
public static ImmutableImage create(int w, int h, Pixel[] pixels, int type)
@Deprecated public static ImmutableImage parse(byte[] bytes) throws java.io.IOException
bytes
- the bytes from the format streamjava.io.IOException
@Deprecated public static ImmutableImage parse(byte[] bytes, int type) throws java.io.IOException
The final image will have the given type. Note, if the image is not stored in the given type, then it will need to be copied. Unless you have a reason to specify the format, use parse(byte[]) and allow the image readers to choose the most appropriate type.
bytes
- the bytes from the format streamjava.io.IOException
public ImmutableImage autocrop()
public ImmutableImage autocrop(java.awt.Color color)
public ImmutableImage autocrop(java.awt.Color color, int colorTolerance)
Eg, if an image had a 20 pixel row of white at the top, and this method was invoked with Color.WHITE then the image returned would have that 20 pixel row removed.
This method is useful when images have an abudance of a single colour around them.
color
- the color to matchcolorTolerance
- the amount of tolerance to use when determining whether the color matches the reference color [0..255]public ImmutableImage blank()
public ImmutableImage bound(int w, int h)
public ImmutableImage bound(int w, int h, ScaleMethod scaleMethod)
If the current image is already within the given dimensions then the same image will be returned. If not, then a scaled image, with the same aspect ratio as the original, and with dimensions inside the constraints will be returned.
This operation differs from max, in that max will scale an image up to be as large as it can be inside the constraints. Bound will keep the image the same if its already within the constraints.
w
- the maximum widthh
- the maximum heightpublic ImmutableImage brightness(double factor)
public ImmutableImage copy()
public ImmutableImage copy(int type)
public ImmutableImage composite(Composite composite, ImmutableImage applicative)
composite
- the composite to use. See com.sksamuel.scrimage.Composite.applicative
- the image to apply with the composite.public ImageMetadata getMetadata()
public ImmutableImage contrast(double factor)
public ImmutableImage cover(int targetWidth, int targetHeight)
public ImmutableImage cover(int targetWidth, int targetHeight, Position position)
public ImmutableImage cover(int targetWidth, int targetHeight, ScaleMethod scaleMethod, Position position)
If the given dimensions have a different aspect ratio than this image then the image will be cropped so that it still covers the new area without leaving any background.
In other words, the image "covers" the target dimensions with the potential loss of some of the image if the aspect ratio change. Similar to taking a 16:9 movie and resizing it for a 4:3 screen. You can either lose part of the image (this operation) or resize it so there is empty space on two sides (the fit operation).
targetWidth
- the target widthtargetHeight
- the target heightscaleMethod
- the type of scaling method to use. Defaults to Bicubicposition
- where to position the image inside the new canvaspublic ImmutableImage fill(java.awt.Color color)
public ImmutableImage fill(Painter painter)
public ImmutableImage filter(Filter... filters) throws java.io.IOException
filters
- the sequence filters to applyjava.io.IOException
public ImmutableImage filter(Filter filter) throws java.io.IOException
filter
- the filter to apply. See com.sksamuel.scrimage.Filter.java.io.IOException
public ImmutableImage fit(int canvasWidth, int canvasHeight)
public ImmutableImage fit(int canvasWidth, int canvasHeight, ScaleMethod scaleMethod)
public ImmutableImage fit(int canvasWidth, int canvasHeight, java.awt.Color color)
public ImmutableImage fit(int canvasWidth, int canvasHeight, java.awt.Color color, Position position)
public ImmutableImage fit(int canvasWidth, int canvasHeight, java.awt.Color color, ScaleMethod scaleMethod, Position position)
In other words, the image "fits" the target dimensions without losing any of the image if the aspect ratio change. Similar to taking a 16:9 movie and resizing it for a 4:3 screen. You can either lose part of the image (cover operation) or resize it so there is empty space on two sides (this operation).
canvasWidth
- the target widthcanvasHeight
- the target heightscaleMethod
- the algorithm to use for the scaling operation. See ScaleMethod.color
- the color to use as the "padding" colour should the scaled original not fit exactly inside the new dimensionsposition
- where to position the image inside the new canvaspublic RGBColor[] quantize(int colours)
colours
- how many colours to quantize for.public ImmutableImage flipX()
public ImmutableImage flipY()
public ImmutableImage max(int maxW, int maxH)
public ImmutableImage max(int maxW, int maxH, ScaleMethod scaleMethod)
For an operation that will scale an image as well as add padding to fit the dimensions perfectly, then use fit. For an operation that will only resize smaller, and not larger, see bound.
Requesting a bound of 200,200 on an image of 300,600 will result in a scale to 100,200. Eg, the original image will be scaled down to fit the bounds.
Requesting a bound of 150,200 on an image of 150,150 will result in the same image being returned. Eg, the original image cannot be scaled up any further without exceeding the bounds.
Requesting a bound of 300,300 on an image of 100,150 will result in a scale to 200,300.
Requesting a bound of 100,1000 on an image of 50,50 will result in a scale to 100,100.
maxW
- the maximum widthmaxH
- the maximum heightpublic ImmutableImage op(java.awt.image.BufferedImageOp op)
public ImmutableImage overlay(AwtImage overlayImage)
If the image to render exceeds the boundaries of the source image, then the excess pixels will be ignored.
public ImmutableImage overlay(AwtImage overlayImage, int x, int y)
public ImmutableImage resize(double scaleFactor)
public ImmutableImage resize(double scaleFactor, Position position)
public ImmutableImage resize(double scaleFactor, java.awt.Color background)
public ImmutableImage resize(double scaleFactor, Position position, java.awt.Color background)
scaleFactor
- the scaleFactor. 1 retains original size. 0.5 is half. 2 double. etcposition
- where to position the original image after the canvas size change. Defaults to centre.background
- the color to use for expande background areas.public ImmutableImage resizeTo(int targetWidth, int targetHeight)
public ImmutableImage resizeTo(int targetWidth, int targetHeight, Position position)
public ImmutableImage resizeTo(int targetWidth, int targetHeight, java.awt.Color color)
public ImmutableImage resizeTo(int targetWidth, int targetHeight, Position position, java.awt.Color background)
If the dimensions are smaller than the current canvas size then the image will be cropped.
The position parameter determines how the original image will be positioned on the new canvas.
targetWidth
- the target widthtargetHeight
- the target heightposition
- where to position the original image after the canvas size changebackground
- the background color if the canvas was enlargedpublic ImmutableImage resizeToRatio(double targetRatio)
public ImmutableImage resizeToRatio(double targetRatio, Position position, java.awt.Color background)
Depending on ratio will increase either width or height.
The position parameter determines how the original image will be positioned on the new canvas.
targetRatio
- width divided by heightposition
- where to position the original image after the canvas size changebackground
- the background color if the canvas was enlargedpublic ImmutableImage resizeToHeight(int targetHeight)
public ImmutableImage resizeToHeight(int targetHeight, Position position, java.awt.Color background)
position
- where to position the original image after the canvas size changepublic ImmutableImage resizeToWidth(int targetWidth)
public ImmutableImage resizeToWidth(int targetWidth, Position position, java.awt.Color background)
position
- where to position the original image after the canvas size changepublic ImmutableImage rotateLeft()
public ImmutableImage rotateRight()
public ImmutableImage rotate(Radians radians)
public ImmutableImage rotate(Degrees degrees)
public ImmutableImage pad(int size, java.awt.Color color)
Eg, requesting a pad of 30 on an image of 250,300 will result in a new image with a canvas size of 310,360
size
- the number of pixels to add on each edgecolor
- the background of the padded area.public ImmutableImage padTo(int targetWidth, int targetHeight)
public ImmutableImage padTo(int targetWidth, int targetHeight, java.awt.Color color)
Eg, requesting a pad of 200,200 on an image of 250,300 will result in keeping the 250,300.
Eg2, requesting a pad of 300,300 on an image of 400,250 will result in the width staying at 400 and the height padded to 300.
targetWidth
- the size of the output canvas widthtargetHeight
- the size of the output canvas heightcolor
- the background of the padded area.public ImmutableImage padWith(int left, int top, int right, int bottom)
public ImmutableImage padWith(int left, int top, int right, int bottom, java.awt.Color color)
left
- the number of columns/pixels to add on the lefttop
- the number of rows/pixels to add to the topright
- the number of columns/pixels to add on the rightbottom
- the number of rows/pixels to add to the bottomcolor
- the background of the padded area.public ImmutableImage padTop(int k, java.awt.Color color)
k
- the number of rows to pad bycolor
- the color that should be used for the new rowspublic ImmutableImage padBottom(int k, java.awt.Color color)
k
- the number of rows to pad bycolor
- the color that should be used for the new rowspublic ImmutableImage padLeft(int k)
k
- the number of columns to pad bypublic ImmutableImage padLeft(int k, java.awt.Color color)
k
- the number of columns to pad bycolor
- the color that should be used for the new pixelspublic ImmutableImage padRight(int k)
k
- the number of columns to pad bypublic ImmutableImage padRight(int k, java.awt.Color color)
k
- the number of columns to pad bycolor
- the color that should be used for the new pixelspublic ImmutableImage removeTransparency(java.awt.Color color)
public ImmutableImage scaleToWidth(int targetWidth)
public ImmutableImage scaleToWidth(int targetWidth, ScaleMethod scaleMethod)
scaleToWidth will scale the image so that the new image has a width that matches the given targetWidth and the height is determined by the original aspect ratio.
Eg, an image of 200,300 with a scaleToWidth of 400 will result in a scaled image of 400,600
targetWidth
- the target widthscaleMethod
- the type of scaling method to use.public ImmutableImage scaleToWidth(int targetWidth, ScaleMethod scaleMethod, boolean keepAspectRatio)
public ImmutableImage scaleToHeight(int targetHeight)
public ImmutableImage scaleToHeight(int targetHeight, ScaleMethod scaleMethod)
public ImmutableImage scaleToHeight(int targetHeight, ScaleMethod scaleMethod, boolean keepAspectRatio)
scaleToHeight will scale the image so that the new image has a height that matches the given targetHeight.
If keepAspectRatio is true, then the width will also be scaled so that the aspect ratio of the image does not change. If keepAspectRatio is false, then the width will stay the same.
Eg, an image of 200,300 with a scaleToHeight of 450 and keepAspectRatio of true will result in a scaled image of 300,450 (because 300 to 450 is 1.5 and so 200 x 1.5 is 300).
targetHeight
- the target heightscaleMethod
- the type of scaling method to use.keepAspectRatio
- whether the width should also be scaled to keep the aspect ratio the same.public ImmutableImage scaleHeightToRatio(double ratio)
public ImmutableImage scaleHeightToRatio(double ratio, ScaleMethod scaleMethod)
public ImmutableImage scale(double scaleFactor)
public ImmutableImage scale(double scaleFactor, ScaleMethod scaleMethod)
scaleFactor
- the target increase or decrease. 1 is the same as original.scaleMethod
- the type of scaling method to use.public ImmutableImage scaleTo(int targetWidth, int targetHeight)
public ImmutableImage scaleTo(int targetWidth, int targetHeight, ScaleMethod scaleMethod)
The size of the scaled instance are taken from the given width and height parameters.
targetWidth
- the target widthtargetHeight
- the target heightscaleMethod
- the type of scaling method to use. Defaults to SmoothScalepublic ImmutableImage subpixelSubimage(double x, double y, int subWidth, int subHeight)
public ImmutableImage subpixelSubimageCenteredAtPoint(double x, double y, double xRadius, double yRadius)
public ImmutableImage subimage(int x, int y, int w, int h)
x
- the start x coordinatey
- the start y coordinatew
- the width of the subimageh
- the height of the subimagepublic ImmutableImage subimage(java.awt.Rectangle rectangle)
public ImmutableImage takeLeft(int k)
public ImmutableImage takeRight(int k)
public ImmutableImage takeTop(int k)
public ImmutableImage takeBottom(int k)
public ImmutableImage translate(int x, int y)
This method will use transparency for the color of the displaced pixels.
public ImmutableImage translate(int x, int y, java.awt.Color bg)
public ImmutableImage trim(int amount)
amount
- the number of pixels to trim from each edgepublic ImmutableImage trim(int left, int top, int right, int bottom)
left
- the number of pixels to trim from the lefttop
- the number of pixels to trim from the topright
- the number of pixels to trim from the rightbottom
- the number of pixels to trim from the bottompublic ImmutableImage trimLeft(int k)
k
- how many columns of pixels to removepublic ImmutableImage trimRight(int k)
k
- how many columns of pixels to removepublic ImmutableImage trimBottom(int k)
k
- how many rows of pixels to removepublic ImmutableImage trimTop(int k)
k
- how many rows of pixels to removepublic ImmutableImage underlay(ImmutableImage underlayImage)
public ImmutableImage underlay(ImmutableImage underlayImage, int x, int y)
If the image to render exceeds the boundaries of the source image, then the excess pixels will be ignored.
public ImmutableImage associateMetadata(ImageMetadata metadata)
Both the original and the new image will share a buffer
public ImmutableImage zoom(double factor)
public ImmutableImage zoom(double factor, ScaleMethod method)
This can be thought of as zooming in on a camera - the viewpane does not change but the image increases in size with the outer columns/rows being dropped as required.
factor
- how much to zoom bymethod
- how to apply the scaling methodpublic ImmutableImage map(java.util.function.Function<Pixel,java.awt.Color> mapper)
The function accepts a pixel being transformed and returns a new (or same) color.
mapper
- the function to transform pixel x,y with existing value p into new pixel value p' (p prime)public Canvas toCanvas()
public WriteContext forWriter(ImageWriter writer)
public ImmutableImage overlay(ImmutableImage image, Position position)
public ImmutableImage transform(Transform transform) throws java.io.IOException
java.io.IOException