public abstract class Image extends Object implements Hashable
Images are immutable. All the methods transforming an image, e.g.
crop(int, int, int, int)
, return a new image which is the result of
the transformation and leave the original image unmodified.
All methods return serializable images as long as this
and the
arguments are serializable.
Example:
Image im = Images.canvas(80, 80, Color.PLUM_1)
.fill(Color.PLUM_2, Gradients.linear(Direction.TOP))
.mask(Shapers.roundedBox(8), new Border(1, Color.PLUM_3, 0.5))
.pasteThat(TangoIcon.APPLICATIONS_MULTIMEDIA.toImage(32), 24, 24);
Images.show(im);
Images
Constructor and Description |
---|
Image() |
Modifier and Type | Method and Description |
---|---|
Image |
concatX(Image rightIm)
Returns the image obtained by pasting the given image to the right of this
image.
|
Image |
concatY(Image bottomIm)
Returns the image obtained by pasting the given image at the bottom of this
image.
|
Image |
crop(int rectX,
int rectY,
int rectWidth,
int rectHeight)
Returns a rectangular region from this image.
|
Image |
erase(double rate)
Returns the image obtained by erasing this image uniformly.
|
Image |
erase(Gradient grad)
Returns the image obtained by erasing this image gradually.
|
Image |
fill(Color color,
double alpha)
Returns the image obtained by filling this image uniformly.
|
Image |
fill(Color color,
Gradient grad)
Returns the image obtained by filling this image gradually.
|
Image |
flipX()
Returns the image obtained by flipping this image along the horizontal
axis.
|
Image |
flipY()
Returns the image obtained by flipping this image along the vertical axis.
|
Image |
frame(Color backgroundColor)
Returns the image obtained by pasting this image on top of a monochromatic
opaque image.
|
Image |
frame(Color backgroundColor,
int topPadding,
int rightPadding,
int bottomPadding,
int leftPadding)
Returns the image obtained by pasting this image on top of a larger
monochromatic opaque image.
|
abstract double |
getAlpha(Point p)
Returns the opacity (between 0 and 1) at the given point.
|
abstract Color |
getColor(Point p)
Returns the color at the given point.
|
int |
hashCode() |
abstract int |
height()
Returns the height of the image.
|
Image |
mask(Shape shape)
Returns the image obtained by making all the points lying outside the given
shape transparent.
|
Image |
mask(Shape shape,
Border... borders)
Returns the image obtained by making all the points lying outside the given
shape transparent and drawing borders around the shape.
|
Image |
mask(Shaper shaper)
Returns the image obtained by making all the points lying outside the given
shape transparent.
|
Image |
mask(Shaper shaper,
Border... borders)
Returns the image obtained by making all the points lying outside the given
shape transparent and drawing borders around the shape.
|
Image |
pasteThat(Image that)
Returns the image obtained by pasting that image on top of this image.
|
Image |
pasteThat(Image that,
int destX,
int destY)
Returns the image obtained by pasting that image on top of this image, at
the given position.
|
Image |
pasteThis(Image that)
Returns the image obtained by pasting this image on top of that image.
|
Image |
pasteThis(Image that,
int destX,
int destY)
Returns the image obtained by pasting this image on top of that image, at
the given position.
|
Image |
rotateCcw()
Returns the image obtained by rotating this image counterclockwise.
|
Image |
rotateCw()
Returns the image obtained by rotating this image clockwise.
|
Image |
scale(int newWidth,
int newHeight)
Returns the image obtained by resizing this image.
|
abstract int |
width()
Returns the width of the image.
|
public abstract int width()
public abstract int height()
public abstract Color getColor(Point p)
p
- a point in the image boundspublic abstract double getAlpha(Point p)
p
- a point in the image boundspublic Image concatX(Image rightIm)
![]() |
![]() |
![]() |
im1 |
im2 |
im1.concatX(im2) |
rightIm
- the image to paste to the right of this imageIllegalArgumentException
- if the two images don't have the same
heightpublic Image concatY(Image bottomIm)
![]() |
![]() |
![]() |
im1 |
im2 |
im1.concatY(im2) |
bottomIm
- the image to paste at the bottom of this imageIllegalArgumentException
- if the two images don't have the same
widthpublic Image flipX()
![]() |
![]() |
im |
im.flipX() |
public Image flipY()
![]() |
![]() |
im |
im.flipY() |
public final Image frame(Color backgroundColor)
![]() |
![]() |
im |
im.frame(CHOCOLATE_1) |
backgroundColor
- the color of the background imagepublic Image frame(Color backgroundColor, int topPadding, int rightPadding, int bottomPadding, int leftPadding)
![]() |
![]() |
im |
im.frame(CHOCOLATE_1, 10, 20, 40, 10) |
backgroundColor
- the color of the background imagetopPadding
- the height of the top border. Can be negative.rightPadding
- the width of the right border. Can be negative.bottomPadding
- the height of the bottom border. Can be negative.leftPadding
- the width of the left border. Can be negative.IllegalArgumentException
- if the new image has a negative width or
height (in the case of negative padding)public Image crop(int rectX, int rectY, int rectWidth, int rectHeight)
![]() |
![]() |
im |
im.crop(10, 10, 60, 30) |
rectX
- the x-coordinate of the left side of the rectangle. Must be
positive.rectY
- the y-coordinate of the top side of the rectangle. Must be
positive.rectWidth
- the width of the rectangle. Must be positive.rectHeight
- the height of the rectangle. Must be positive.IllegalArgumentException
- if rectX
, rectY
,
rectWidth
or rectHeight
is negativeIndexOutOfBoundsException
- if rectX
+ rectWidth
>
getWidth()
, or rectY
+ rectHeight
>
getHeight()
public Image rotateCw()
![]() |
![]() |
im |
im.rotateCw() |
public Image rotateCcw()
![]() |
![]() |
im |
im.rotateCcw() |
public Image scale(int newWidth, int newHeight)
![]() |
![]() |
im |
im.scale(200, 100) |
newWidth
- the width of the new image. Must be positive.newHeight
- the height of the new image. Must be positive.IllegalArgumentException
- if the width or the height of the new
image is negativepublic Image erase(double rate)
![]() |
![]() |
im |
im.erase(0.75) |
rate
- the rate, between 0 and 1. 0 returns this image, 1 returns a
transparent image.IllegalArgumentException
- if the rate is not between 0 and 1public Image erase(Gradient grad)
![]() |
![]() |
im |
im.erase(Gradients.linear(BOTTOM)) |
grad
- the gradientpublic Image fill(Color color, double alpha)
![]() |
![]() |
im |
im.fill(WHITE, 0.25) |
color
- the color to fill the image withalpha
- the opacity of the new layer, between 0 and 1. 0 returns this
image, 1 returns a monochromatic image.IllegalArgumentException
- if the opacity is not between 0 and 1public Image fill(Color color, Gradient grad)
![]() |
![]() |
im |
im.fill(CHOCOLATE_1, Gradients.circular(2, -0.5)) |
color
- the color to fill the image withgrad
- the gradient the gradientpublic Image pasteThat(Image that, int destX, int destY)
![]() |
![]() |
![]() |
im1 |
im2 |
im1.pasteThat(im2, 24, 24) |
that
- the image to paste on top of this imagedestX
- the y-coordinate at which to paste that imagedestY
- the y-coordinate at which to paste that imagepasteThis(Image, int, int)
public final Image pasteThis(Image that, int destX, int destY)
![]() |
![]() |
![]() |
im1 |
im2 |
im1.pasteThis(im2, 24, 24) |
that
- the image to paste this image on top ofdestX
- the x-coordinate at which to paste this imagedestY
- the y-coordinate at which to paste this imagepasteThat(Image, int, int)
public final Image pasteThat(Image that)
![]() |
![]() |
![]() |
im1 |
im2 |
im1.pasteThat(im2) |
that
- the image to paste on top of this imageIllegalArgumentException
- if the two images don't have the same sizepasteThis(Image)
public final Image pasteThis(Image that)
![]() |
![]() |
![]() |
im1 |
im2 |
im1.pasteThis(im2) |
that
- the image to paste this image on top ofIllegalArgumentException
- if the two images don't have the same sizepasteThat(Image)
public Image mask(Shape shape)
![]() |
![]() |
im |
im.mask(Shapes.ellipse(10, 10, 60, 60)) |
shape
- the shapemask(Shape, Border[])
public Image mask(Shape shape, Border... borders)
![]() |
![]() |
im |
|
shape
- the shapeborders
- the borders, from outside to insidemask(Shape)
public final Image mask(Shaper shaper)
![]() |
![]() |
im |
im.mask(Shapers.roundedBox(8)) |
shaper
- the shaper to generate the shapemask(Shaper, Border[])
public final Image mask(Shaper shaper, Border... borders)
![]() |
![]() |
im |
|
shaper
- the shaper to generate the shapeborders
- the borders, from outside to insidemask(Shaper)
Copyright © 2013. All Rights Reserved.