Package codedraw.images
Class CodeDrawImage
java.lang.Object
codedraw.images.CodeDrawImage
CodeDrawImage represents an image that can be used within the CodeDraw library.
Empty images can be created via the constructor.
CodeDrawImage image = new CodeDrawImage(400, 600);
External images can be loaded via static methods.
CodeDrawImage image = CodeDrawImage.fromFile("/directory/filename.png");
-
Constructor Summary
ConstructorDescriptionCodeDrawImage
(int width, int height) Creates a white CodeDrawImage of the specified size.CodeDrawImage
(CodeDrawImage image) Creates a copy of the CodeDrawImage supplied as a parameter.CodeDrawImage
(Image image) Creates a CodeDrawImage from the Image supplied as a parameter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Colors the whole canvas in white.void
Colors the whole canvas in the color given as a parameter.Creates a copy of this CodeDrawImage in the form of a BufferedImage.void
copyTo
(Graphics target, Interpolation interpolation) Copies this CodeDrawImage onto the graphics object.void
drawArc
(double x, double y, double radius, double startRadians, double sweepRadians) Draws the outline of an arc with the center being the (x, y) coordinates.void
drawArc
(double x, double y, double horizontalRadius, double verticalRadius, double startRadians, double sweepRadians) Draws the outline of an arc with the center being the (x, y) coordinates.void
drawBezier
(double startX, double startY, double control1X, double control1Y, double control2X, double control2Y, double endX, double endY) Draws a cubic Bézier curve.void
drawCircle
(double x, double y, double radius) Draws the outline of a circle.void
drawCurve
(double startX, double startY, double controlX, double controlY, double endX, double endY) Draws a quadratic Bézier curve.void
drawEllipse
(double x, double y, double horizontalRadius, double verticalRadius) Draws the outline of an ellipse.void
drawImage
(double x, double y, double width, double height, CodeDrawImage image) Draws an image at the specified (x, y) coordinate.void
drawImage
(double x, double y, double width, double height, CodeDrawImage image, Interpolation interpolation) Draws an image at the specified (x, y) coordinate.void
drawImage
(double x, double y, CodeDrawImage image) Draws an image at the specified (x, y) coordinate.void
drawLine
(double startX, double startY, double endX, double endY) Draws a straight line between the start point and end point.void
drawPie
(double x, double y, double radius, double startRadians, double sweepRadians) Draws the outline of a pie with the center being the (x, y) coordinates.void
drawPie
(double x, double y, double horizontalRadius, double verticalRadius, double startRadians, double sweepRadians) Draws the outline of a pie with the center being the (x, y) coordinates.void
drawPixel
(double x, double y) Draws a point which is exactly 1x1 pixel in size.void
drawPoint
(double x, double y) Draws a point which changes size depending on thegetLineWidth()
void
drawPolygon
(double... points) Draws the outline of a polygon.void
drawRectangle
(double x, double y, double width, double height) Draws the outline of a rectangle.void
drawSquare
(double x, double y, double sideLength) Draws the outline of a square.void
Draws the text at the specified (x, y) coordinate.void
drawTriangle
(double x1, double y1, double x2, double y2, double x3, double y3) Draws the outline of a triangle.void
fillCircle
(double x, double y, double radius) Draws a filled circle.void
fillEllipse
(double x, double y, double horizontalRadius, double verticalRadius) Draws a filled ellipse.void
fillPie
(double x, double y, double radius, double startRadians, double sweepRadians) Draws a filled pie with the center being the (x, y) coordinates.void
fillPie
(double x, double y, double horizontalRadius, double verticalRadius, double startRadians, double sweepRadians) Draws a filled pie with the center being the (x, y) coordinates.void
fillPolygon
(double... points) Draws a filled polygon.void
fillRectangle
(double x, double y, double width, double height) Draws a filled rectangle.void
fillSquare
(double x, double y, double sideLength) Draws a filled square.void
fillTriangle
(double x1, double y1, double x2, double y2, double x3, double y3) Draws a filled triangle.static CodeDrawImage
fromBase64String
(String base64) Converts a Base64 string into a CodeDrawImage.static CodeDrawImage
fromDPIAwareSize
(int width, int height) Creates a CodeDraw image with an up-scaled resolution.static CodeDrawImage
Loads an image from the file system.static CodeDrawImage
fromResource
(String resourceName) Loads CodeDrawImages from the resource folder.static CodeDrawImage
Loads an image file from the internet.getColor()
Defines the color that is used for drawing all shapes.Defines how the corners of drawn shapes should look.int
This value cannot be changed once set via the constructor.double
Defines the width or thickness of drawn shapes and lines.Defines the styling of drawn text.int
getWidth()
This value cannot be changed once set via the constructor.boolean
Defines whether draw text, drawn shapes and filled shapes are anti-aliased.static void
saveAs
(CodeDrawImage image, String pathToImage, ImageFormat format) Saves the image to the specified location using the specified image format.void
setAntiAliased
(boolean isAntiAliased) Defines whether drawn text, drawn shapes and filled shapes are anti-aliased.void
Defines the color that is used for drawing all shapes.void
Defines how the corners of drawn shapes should look.void
setLineWidth
(double lineWidth) Defines the width or thickness of drawn shapes and lines.void
setTextFormat
(TextFormat textFormat) Defines the styling of drawn text.
-
Constructor Details
-
CodeDrawImage
Creates a copy of the CodeDrawImage supplied as a parameter. The configuration of the CodeDrawImage will not be copied. All parameters of the result will be set to their default value. DPI aware scaling will also be ignored.- Parameters:
image
- Image that is to be copied.
-
CodeDrawImage
Creates a CodeDrawImage from the Image supplied as a parameter. The contents of the supplied image will be copied to create this new CodeDrawImage instance.- Parameters:
image
- Image that is to be converted to a CodeDrawImage.
-
CodeDrawImage
public CodeDrawImage(int width, int height) Creates a white CodeDrawImage of the specified size.- Parameters:
width
- The width of the CodeDrawImage.height
- The height of the CodeDrawImage.
-
-
Method Details
-
fromFile
Loads an image from the file system. Supported image formats: .jpg or .jpeg (JPEG), .bmp (Bitmap), .gif (Graphics Interchange Format), .png (Portable Network Graphic) and .wbmp (Wireless Application Protocol Bitmap Format).ImageIO.read(File)
is used to read images from the file system.- Parameters:
pathToImage
- A string that points to an image file.- Returns:
- An image.
-
fromUrl
Loads an image file from the internet. This function might be very slow depending on speed of the network connection or the availability of the server.
Supported image formats: .jpg or .jpeg (JPEG), .bmp (Bitmap), .gif (Graphics Interchange Format), .png (Portable Network Graphic) and .wbmp (Wireless Application Protocol Bitmap Format).CodeDrawImage image = CodeDrawImage.fromUrl("https://exmaple.com/example-image.png");
ImageIO.read(URL)
is used to load images from the network.- Parameters:
url
- Link to the image file.- Returns:
- An image.
-
fromResource
Loads CodeDrawImages from the resource folder.
Supported image formats: .jpg or .jpeg (JPEG), .bmp (Bitmap), .gif (Graphics Interchange Format), .png (Portable Network Graphic) and .wbmp (Wireless Application Protocol Bitmap Format).CodeDrawImage image = CodeDrawImage.fromResource("./my_image.png");
ImageIO.read(URL)
is used to read images from the resource folder.- Parameters:
resourceName
- Path to the resource from the root of the resource folder.- Returns:
- An image.
-
fromBase64String
Converts a Base64 string into a CodeDrawImage. Supported image formats: .jpg or .jpeg (JPEG), .bmp (Bitmap), .gif (Graphics Interchange Format), .png (Portable Network Graphic) and .wbmp (Wireless Application Protocol Bitmap Format).ImageIO.read(InputStream)
andBase64.Decoder.decode(String)
are used to convert the image.- Parameters:
base64
- a Base64 string- Returns:
- a CodeDrawImage
-
fromDPIAwareSize
Creates a CodeDraw image with an up-scaled resolution. The upscaling factor depends on the highest resolution of all monitors on the current machine. The pixel grid coordinates will be the same as a regular CodeDrawImage but round edges and fractional coordinates will be more precisely drawn.- Parameters:
width
- The width of the CodeDrawImage.height
- The height of the CodeDrawImage.- Returns:
- a CodeDrawImage
-
saveAs
Saves the image to the specified location using the specified image format. Supported formats are all values inImageFormat
. The formatsImageFormat.JPG
,ImageFormat.JPEG
andImageFormat.BMP
do not support transparency.ImageIO.write(RenderedImage, String, File)
andFile(String)
are used to read the image from the file system. Read their documentation for more details.- Parameters:
image
- a CodeDrawImagepathToImage
- The location where the image should be saved.format
- The format the image should be saved in. As a default chooseImageFormat.PNG
and make sure that the file ends with ".png".
-
getWidth
public int getWidth()This value cannot be changed once set via the constructor.- Returns:
- the width of the canvas.
-
getHeight
public int getHeight()This value cannot be changed once set via the constructor.- Returns:
- the height of the canvas.
-
getColor
Defines the color that is used for drawing all shapes.- Returns:
- the drawing color of this CodeDraw window.
-
setColor
Defines the color that is used for drawing all shapes. UsePalette
for a large selection of colors.- Parameters:
color
- Sets the drawing color of this CodeDraw window.
-
getLineWidth
public double getLineWidth()Defines the width or thickness of drawn shapes and lines. Must be greater than zero.- Returns:
- the lineWidth of this CodeDraw window.
-
setLineWidth
public void setLineWidth(double lineWidth) Defines the width or thickness of drawn shapes and lines. Must be greater than zero.- Parameters:
lineWidth
- Sets the lineWidth of this CodeDraw window.
-
getCorner
Defines how the corners of drawn shapes should look. SeeCorner
for details.- Returns:
- the corner style of this CodeDraw window.
-
setCorner
Defines how the corners of drawn shapes should look. SeeCorner
for details.- Parameters:
corner
- Sets the corner style of this CodeDraw window.
-
getTextFormat
Defines the styling of drawn text. See alsodrawText(double, double, String)
on how the styling is applied.- Returns:
- the text formatting options of this CodeDraw window.
-
setTextFormat
Defines the styling of drawn text. See alsodrawText(double, double, String)
on how the styling is applied.- Parameters:
textFormat
- Sets the text formatting options of this CodeDraw window.
-
isAntiAliased
public boolean isAntiAliased()Defines whether draw text, drawn shapes and filled shapes are anti-aliased. See Wikipedia Spatial Anti-aliasing- Returns:
- Whether this CodeDraw window anti aliases.
-
setAntiAliased
public void setAntiAliased(boolean isAntiAliased) Defines whether drawn text, drawn shapes and filled shapes are anti-aliased. See Wikipedia Spatial Anti-aliasing- Parameters:
isAntiAliased
- Sets whether this CodeDraw window anti aliases.
-
drawText
Draws the text at the specified (x, y) coordinate. Formatting options can be set via the TextFormat object. SeegetTextFormat()
,setTextFormat(TextFormat)
and theTextFormat
class. If not specified otherwise in the TextFormat object the (x, y) coordinates will be in the top left corner of the text.- Parameters:
x
- The distance in pixel from the left side of the canvas.y
- The distance in pixel from the top side of the canvas.text
- The text or string to be drawn.
-
drawPixel
public void drawPixel(double x, double y) Draws a point which is exactly 1x1 pixel in size.- Parameters:
x
- The distance in pixel from the left side of the canvas.y
- The distance in pixel from the top side of the canvas.
-
drawPoint
public void drawPoint(double x, double y) Draws a point which changes size depending on thegetLineWidth()
- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the point.y
- The distance in pixel from the top side of the canvas to the center of the point.
-
drawLine
public void drawLine(double startX, double startY, double endX, double endY) Draws a straight line between the start point and end point. The line width can be changed withsetLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
startX
- The distance in pixel from the left side of the canvas to the start of the line.startY
- The distance in pixel from the top side of the canvas to the start of the line.endX
- The distance in pixel from the left side of the canvas to the end of the line.endY
- The distance in pixel from the top side of the canvas to the end of the line.
-
drawCurve
public void drawCurve(double startX, double startY, double controlX, double controlY, double endX, double endY) Draws a quadratic Bézier curve. See: Wikipedia Bezier Curve The start and end of the curve will be precisely where startX/Y and endX/Y are specified. The controlX/Y parameter specifies in what way the curve will be bent. The line width can be changed withsetLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
startX
- The distance in pixel from the left side of the canvas to the start of the curve.startY
- The distance in pixel from the top side of the canvas to the start of the curve.controlX
- Defines the way the curve bends in the x direction.controlY
- Defines the way the curve bends in the y direction.endX
- The distance in pixel from the left side of the canvas to the end of the curve.endY
- The distance in pixel from the top side of the canvas to the end of the curve.
-
drawBezier
public void drawBezier(double startX, double startY, double control1X, double control1Y, double control2X, double control2Y, double endX, double endY) Draws a cubic Bézier curve. See Wikipedia Bezier Curve The start and end of the curve will be precisely where startX/Y and endX/Y are specified. The control1X/Y and control2X/Y parameter specify in what way the curve will be bent. The line width can be changed withsetLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
startX
- The distance in pixel from the left side of the canvas to the start of the curve.startY
- The distance in pixel from the top side of the canvas to the start of the curve.control1X
- Defines the way the curve bends in the x direction.control1Y
- Defines the way the curve bends in the y direction.control2X
- Defines the way the curve bends in the x direction.control2Y
- Defines the way the curve bends in the y direction.endX
- The distance in pixel from the left side of the canvas to the end of the curve.endY
- The distance in pixel from the top side of the canvas to the end of the curve.
-
drawSquare
public void drawSquare(double x, double y, double sideLength) Draws the outline of a square. The line width can be changed withsetLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left size of the square.y
- The distance in pixel from the top side of the canvas to the top side of the square.sideLength
- The width and the height of the square in pixel.
-
fillSquare
public void fillSquare(double x, double y, double sideLength) Draws a filled square. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left size of the square.y
- The distance in pixel from the top side of the canvas to the top side of the square.sideLength
- The width and the height of the square in pixel.
-
drawRectangle
public void drawRectangle(double x, double y, double width, double height) Draws the outline of a rectangle. The line width can be changed withsetLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left size of the rectangle.y
- The distance in pixel from the top side of the canvas to the top side of the rectangle.height
- The height of the rectangle in pixel.width
- The width of the rectangle in pixel.
-
fillRectangle
public void fillRectangle(double x, double y, double width, double height) Draws a filled rectangle. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left size of the rectangle.y
- The distance in pixel from the top side of the canvas to the top side of the rectangle.height
- The height of the rectangle in pixel.width
- The width of the rectangle in pixel.
-
drawCircle
public void drawCircle(double x, double y, double radius) Draws the outline of a circle. The center of the circle will be at the specified (x, y) coordinate. The line width can be changed withsetLineWidth(double)
.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the circle.y
- The distance in pixel from the top side of the canvas to the center of the circle.radius
- The radius of the circle in pixel.
-
fillCircle
public void fillCircle(double x, double y, double radius) Draws a filled circle. The center of the circle will be at the specified (x, y) coordinate.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the circle.y
- The distance in pixel from the top side of the canvas to the center of the circle.radius
- The radius of the circle in pixel.
-
drawEllipse
public void drawEllipse(double x, double y, double horizontalRadius, double verticalRadius) Draws the outline of an ellipse. The center of the ellipse will be at the specified (x, y) coordinate. The line width can be changed withsetLineWidth(double)
.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the ellipse.y
- The distance in pixel from the top side of the canvas to the center of the ellipse.horizontalRadius
- The horizontal radius of the ellipse in pixel. The width of the ellipse is 2 * horizontalRadius.verticalRadius
- The vertical radius of the ellipse in pixel. The height of the ellipse is 2 * verticalRadius.
-
fillEllipse
public void fillEllipse(double x, double y, double horizontalRadius, double verticalRadius) Draws a filled ellipse. The center of the ellipse will be at the specified (x, y) coordinate.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the ellipse.y
- The distance in pixel from the top side of the canvas to the center of the ellipse.horizontalRadius
- The horizontal radius of the ellipse in pixel. The width of the ellipse is 2 * horizontalRadius.verticalRadius
- The vertical radius of the ellipse in pixel. The height of the ellipse is 2 * verticalRadius.
-
drawArc
public void drawArc(double x, double y, double radius, double startRadians, double sweepRadians) Draws the outline of an arc with the center being the (x, y) coordinates. The arc starts at the 3 o'clock position offset by the startRadians parameter. The total length of the arc is defined by the sweepRadians parameter. The line width can be changed withsetLineWidth(double)
.
You can useMath.toRadians(double)
to specify the angle in degrees.
The line width can be changed withcd.drawArc(200, 200, 50, Math.toRadians(90), Math.toRadians(180));
setLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the arc.y
- The distance in pixel from the top side of the canvas to the center of the arc.radius
- The radius of the arc in pixel.startRadians
- The starting angle in radians. A 0 radians angle would be interpreted as starting at 3 o'clock going clockwise.sweepRadians
- The length of the arc in radians from the start angle in a clockwise direction.
-
drawArc
public void drawArc(double x, double y, double horizontalRadius, double verticalRadius, double startRadians, double sweepRadians) Draws the outline of an arc with the center being the (x, y) coordinates. The width is 2 * horizontalRadius and the height is 2 * verticalRadius. The arc starts at the 3 o'clock position offset by the startRadians parameter. The total length of the arc is defined by the sweepRadians parameter. The line width can be changed withsetLineWidth(double)
.
You can useMath.toRadians(double)
to specify the angle in degrees.
The line width can be changed withcd.drawArc(200, 200, 50, 50, Math.toRadians(90), Math.toRadians(180));
setLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the arc.y
- The distance in pixel from the top side of the canvas to the center of the arc.horizontalRadius
- The horizontal radius of the arc in pixel. The width of the arc is 2 * horizontalRadius.verticalRadius
- The vertical radius of the arc in pixel. The height of the arc is 2 * verticalRadius.startRadians
- The starting angle in radians. A 0 radians angle would be interpreted as starting at 3 o'clock going clockwise.sweepRadians
- The length of the arc in radians from the start angle in a clockwise direction.
-
drawPie
public void drawPie(double x, double y, double radius, double startRadians, double sweepRadians) Draws the outline of a pie with the center being the (x, y) coordinates. The pie starts at the 3 o'clock position offset by the startRadians parameter. The total length of the pie is defined by the sweepRadians parameter. The line width can be changed withsetLineWidth(double)
.
You can useMath.toRadians(double)
to specify the angle in degrees.
The line width can be changed withcd.drawPie(200, 200, 50, Math.toRadians(90), Math.toRadians(180));
setLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the pie.y
- The distance in pixel from the top side of the canvas to the center of the pie.radius
- The radius of the pie in pixel.startRadians
- The starting angle in radians. A 0 radians angle would be interpreted as starting at 3 o'clock going clockwise.sweepRadians
- The length of the pie in radians from the start angle in a clockwise direction.
-
drawPie
public void drawPie(double x, double y, double horizontalRadius, double verticalRadius, double startRadians, double sweepRadians) Draws the outline of a pie with the center being the (x, y) coordinates. The width is 2 * horizontalRadius and the height is the 2 * verticalRadius. The pie starts at the 3 o'clock position offset by the startRadians parameter. The total length of the pie is defined by the sweepRadians parameter. The line width can be changed withsetLineWidth(double)
.
You can useMath.toRadians(double)
to specify the angle in degrees.
The line width can be changed withcd.drawPie(200, 200, 50, 50, Math.toRadians(90), Math.toRadians(180));
setLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the pie.y
- The distance in pixel from the top side of the canvas to the center of the pie.horizontalRadius
- The horizontal radius of the pie in pixel. The width of the pie is 2 * horizontalRadius.verticalRadius
- The vertical radius of the pie in pixel. The height of the pie is 2 * verticalRadius.startRadians
- The starting angle in radians. A 0 radians angle would be interpreted as starting at 3 o'clock going clockwise.sweepRadians
- The length of the pie in radians from the start angle in a clockwise direction.
-
fillPie
public void fillPie(double x, double y, double radius, double startRadians, double sweepRadians) Draws a filled pie with the center being the (x, y) coordinates. The pie starts at the 3 o'clock position offset by the startRadians parameter. The total length of the pie is defined by the sweepRadians parameter.
You can useMath.toRadians(double)
to specify the angle in degrees.cd.fillPie(200, 200, 50, Math.toRadians(90), Math.toRadians(180));
- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the pie.y
- The distance in pixel from the top side of the canvas to the center of the pie.radius
- The radius of the pie in pixel.startRadians
- The starting angle in radians. A 0 radians angle would be interpreted as starting at 3 o'clock going clockwise.sweepRadians
- The length of the pie in radians from the start angle in a clockwise direction.
-
fillPie
public void fillPie(double x, double y, double horizontalRadius, double verticalRadius, double startRadians, double sweepRadians) Draws a filled pie with the center being the (x, y) coordinates. The width is 2 * horizontalRadius and the height is the 2 * verticalRadius. The pie starts at the 3 o'clock position offset by the startRadians parameter. The total length of the pie is defined by the sweepRadians parameter.
You can useMath.toRadians(double)
to specify the angle in degrees.cd.fillPie(200, 200, 50, 50, Math.toRadians(90), Math.toRadians(180));
- Parameters:
x
- The distance in pixel from the left side of the canvas to the center of the pie.y
- The distance in pixel from the top side of the canvas to the center of the pie.horizontalRadius
- The horizontal radius of the pie in pixel. The width of the pie is 2 * horizontalRadius.verticalRadius
- The vertical radius of the pie in pixel. The height of the pie is 2 * verticalRadius.startRadians
- The starting angle in radians. A 0 radians angle would be interpreted as starting at 3 o'clock going clockwise.sweepRadians
- The length of the pie in radians from the start angle in a clockwise direction.
-
drawTriangle
public void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3) Draws the outline of a triangle. The line width can be changed withsetLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
x1
- The distance in pixel from the left side of the canvas to the first corner of the triangle.y1
- The distance in pixel from the top side of the canvas to the first corner of the triangle.x2
- The distance in pixel from the left side of the canvas to the second corner of the triangle.y2
- The distance in pixel from the top side of the canvas to the second corner of the triangle.x3
- The distance in pixel from the left side of the canvas to the third corner of the triangle.y3
- The distance in pixel from the top side of the canvas to the third corner of the triangle.
-
fillTriangle
public void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3) Draws a filled triangle.- Parameters:
x1
- The distance in pixel from the left side of the canvas to the first corner of the triangle.y1
- The distance in pixel from the top side of the canvas to the first corner of the triangle.x2
- The distance in pixel from the left side of the canvas to the second corner of the triangle.y2
- The distance in pixel from the top side of the canvas to the second corner of the triangle.x3
- The distance in pixel from the left side of the canvas to the third corner of the triangle.y3
- The distance in pixel from the top side of the canvas to the third corner of the triangle.
-
drawPolygon
public void drawPolygon(double... points) Draws the outline of a polygon. This function must be called with an even number of parameters. Each parameter pair (x, y) represents a corner of the polygon. Must be called with at least two points as parameter. Each point passed to drawPolygon will be connected to the following points and the last point will be connected to the first point.
The line width can be changed withcd.drawPolygon( 200, 100, 100, 200, 300, 200 );
setLineWidth(double)
. The corners can be changed withsetCorner(Corner)
. For details see theCorner
class.- Parameters:
points
- An even number of doubles. Each pair represents one corner of the polygon.
-
fillPolygon
public void fillPolygon(double... points) Draws a filled polygon. This function must be called with an even number of parameters. Each parameter pair (x, y) represents a corner of the polygon. Must be called with at least two points as parameter. Each point passed to drawPolygon will be connected to the following points and the last point will be connected to the first point. If you pass only two arguments to fillPolygon nothing will be drawn.cd.fillPolygon( 200, 100, 100, 200, 300, 200 );
- Parameters:
points
- An even number of doubles. Each pair represents one corner of the polygon.
-
drawImage
Draws an image at the specified (x, y) coordinate. The width and height of the image will be used to draw the image.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left side of the image.y
- The distance in pixel from the top side of the canvas to the top side of the image.image
- Any image.
-
drawImage
Draws an image at the specified (x, y) coordinate. The image will be rescaled to fit within the width and height given as parameters.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left side of the image.y
- The distance in pixel from the top side of the canvas to the top side of the image.width
- The width of the image on the canvas.height
- The height of the image on the canvas.image
- Any image.
-
drawImage
public void drawImage(double x, double y, double width, double height, CodeDrawImage image, Interpolation interpolation) Draws an image at the specified (x, y) coordinate. The image will be rescaled to fit within the width and height given as parameters.- Parameters:
x
- The distance in pixel from the left side of the canvas to the left side of the image.y
- The distance in pixel from the top side of the canvas to the top side of the image.width
- The width of the image on the canvas.height
- The height of the image on the canvas.image
- Any image.interpolation
- Defines the way the images is interpolated when scaled. SeeInterpolation
.
-
clear
public void clear()Colors the whole canvas in white. -
clear
Colors the whole canvas in the color given as a parameter.- Parameters:
color
- The color the canvas will be colored in.
-
copyTo
Copies this CodeDrawImage onto the graphics object. Also applies an interpolation rendering hint if the graphics target is an instance of Graphics2D.- Parameters:
target
- a graphics object.interpolation
- Defines the way the images is interpolated when drawn onto the graphics object. SeeInterpolation
.
-
convertToBufferedImage
Creates a copy of this CodeDrawImage in the form of a BufferedImage.- Returns:
- a BufferedImage.
-