A filter which performs a perspective distortion on an image.
Coordinates are treated as if the image was a unit square, i.e. the bottom-right corner of the image is at (1, 1).
The filter maps the unit square onto an arbitrary convex quadrilateral or vice versa.
PerspectiveFilter
public PerspectiveFilter()
Construct a PerspectiveFilter.
PerspectiveFilter
public PerspectiveFilter(float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Construct a PerspectiveFilter.
x0
- the new position of the top left cornery0
- the new position of the top left cornerx1
- the new position of the top right cornery1
- the new position of the top right cornerx2
- the new position of the bottom right cornery2
- the new position of the bottom right cornerx3
- the new position of the bottom left cornery3
- the new position of the bottom left corner
filter
public BufferedImage filter(BufferedImage src,
BufferedImage dst)
- filter in interface TransformFilter
getClip
public boolean getClip()
getOriginX
public float getOriginX()
Get the origin of the output image. Use this for working out where to draw your new image.
getOriginY
public float getOriginY()
Get the origin of the output image. Use this for working out where to draw your new image.
quadToUnitSquare
public void quadToUnitSquare(float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Set the transform to map a quadrilateral onto the unit square. When filtering, all coordinates will be scaled
by the size of the image.
x0
- the old position of the top left cornery0
- the old position of the top left cornerx1
- the old position of the top right cornery1
- the old position of the top right cornerx2
- the old position of the bottom right cornery2
- the old position of the bottom right cornerx3
- the old position of the bottom left cornery3
- the old position of the bottom left corner
setClip
public void setClip(boolean clip)
setCorners
public void setCorners(float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Set the new positions of the image corners.
This is the same as unitSquareToQuad, but the coordinates are in image pixels, not relative to the unit square.
This method is provided as a convenience.
x0
- the new position of the top left cornery0
- the new position of the top left cornerx1
- the new position of the top right cornery1
- the new position of the top right cornerx2
- the new position of the bottom right cornery2
- the new position of the bottom right cornerx3
- the new position of the bottom left cornery3
- the new position of the bottom left corner
toString
public String toString()
unitSquareToQuad
public void unitSquareToQuad(float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Set the transform to map the unit square onto a quadrilateral. When filtering, all coordinates will be scaled
by the size of the image.
x0
- the new position of the top left cornery0
- the new position of the top left cornerx1
- the new position of the top right cornery1
- the new position of the top right cornerx2
- the new position of the bottom right cornery2
- the new position of the bottom right cornerx3
- the new position of the bottom left cornery3
- the new position of the bottom left corner