Class CodeDrawImage

java.lang.Object
codedraw.images.CodeDrawImage

public class CodeDrawImage extends Object
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

    Constructors
    Constructor
    Description
    CodeDrawImage(int width, int height)
    Creates a white CodeDrawImage of the specified size.
    Creates a copy of the CodeDrawImage supplied as a parameter.
    Creates a CodeDrawImage from the Image supplied as a parameter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Colors the whole canvas in white.
    void
    clear(Color color)
    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 the getLineWidth()
    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
    drawText(double x, double y, String text)
    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.
    Converts a Base64 string into a CodeDrawImage.
    fromDPIAwareSize(int width, int height)
    Creates a CodeDraw image with an up-scaled resolution.
    fromFile(String pathToImage)
    Loads an image from the file system.
    fromResource(String resourceName)
    Loads CodeDrawImages from the resource folder.
    Loads an image file from the internet.
    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
    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
    setColor(Color color)
    Defines the color that is used for drawing all shapes.
    void
    setCorner(Corner corner)
    Defines how the corners of drawn shapes should look.
    void
    setLineWidth(double lineWidth)
    Defines the width or thickness of drawn shapes and lines.
    void
    Defines the styling of drawn text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CodeDrawImage

      public CodeDrawImage(CodeDrawImage image)
      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

      public CodeDrawImage(Image image)
      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

      public static CodeDrawImage fromFile(String pathToImage)
      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

      public static CodeDrawImage fromUrl(String url)
      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.
      
       CodeDrawImage image = CodeDrawImage.fromUrl("https://exmaple.com/example-image.png");
       
      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(URL) is used to load images from the network.
      Parameters:
      url - Link to the image file.
      Returns:
      An image.
    • fromResource

      public static CodeDrawImage fromResource(String resourceName)
      Loads CodeDrawImages from the resource folder.
      
       CodeDrawImage image = CodeDrawImage.fromResource("./my_image.png");
       
      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(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

      public static CodeDrawImage fromBase64String(String base64)
      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) and Base64.Decoder.decode(String) are used to convert the image.
      Parameters:
      base64 - a Base64 string
      Returns:
      a CodeDrawImage
    • fromDPIAwareSize

      public static CodeDrawImage fromDPIAwareSize(int width, int height)
      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

      public static void saveAs(CodeDrawImage image, String pathToImage, ImageFormat format)
      Saves the image to the specified location using the specified image format. Supported formats are all values in ImageFormat. The formats ImageFormat.JPG, ImageFormat.JPEG and ImageFormat.BMP do not support transparency. ImageIO.write(RenderedImage, String, File) and File(String) are used to read the image from the file system. Read their documentation for more details.
      Parameters:
      image - a CodeDrawImage
      pathToImage - The location where the image should be saved.
      format - The format the image should be saved in. As a default choose ImageFormat.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

      public Color getColor()
      Defines the color that is used for drawing all shapes.
      Returns:
      the drawing color of this CodeDraw window.
    • setColor

      public void setColor(Color color)
      Defines the color that is used for drawing all shapes. Use Palette 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

      public Corner getCorner()
      Defines how the corners of drawn shapes should look. See Corner for details.
      Returns:
      the corner style of this CodeDraw window.
    • setCorner

      public void setCorner(Corner corner)
      Defines how the corners of drawn shapes should look. See Corner for details.
      Parameters:
      corner - Sets the corner style of this CodeDraw window.
    • getTextFormat

      public TextFormat getTextFormat()
      Defines the styling of drawn text. See also drawText(double, double, String) on how the styling is applied.
      Returns:
      the text formatting options of this CodeDraw window.
    • setTextFormat

      public void setTextFormat(TextFormat textFormat)
      Defines the styling of drawn text. See also drawText(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

      public void drawText(double x, double y, String text)
      Draws the text at the specified (x, y) coordinate. Formatting options can be set via the TextFormat object. See getTextFormat(), setTextFormat(TextFormat) and the TextFormat 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 the getLineWidth()
      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 with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setCorner(Corner). For details see the Corner 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 with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setCorner(Corner). For details see the Corner 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 with setLineWidth(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 with setLineWidth(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 with setLineWidth(double).
      You can use Math.toRadians(double) to specify the angle in degrees.
      
       cd.drawArc(200, 200, 50, Math.toRadians(90), Math.toRadians(180));
       
      The line width can be changed with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setLineWidth(double).
      You can use Math.toRadians(double) to specify the angle in degrees.
      
       cd.drawArc(200, 200, 50, 50, Math.toRadians(90), Math.toRadians(180));
       
      The line width can be changed with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setLineWidth(double).
      You can use Math.toRadians(double) to specify the angle in degrees.
      
       cd.drawPie(200, 200, 50, Math.toRadians(90), Math.toRadians(180));
       
      The line width can be changed with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 with setLineWidth(double).
      You can use Math.toRadians(double) to specify the angle in degrees.
      
       cd.drawPie(200, 200, 50, 50, Math.toRadians(90), Math.toRadians(180));
       
      The line width can be changed with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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 use Math.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 use Math.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 with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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.
      
       cd.drawPolygon(
           200, 100,
           100, 200,
           300, 200
       );
       
      The line width can be changed with setLineWidth(double). The corners can be changed with setCorner(Corner). For details see the Corner 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

      public void drawImage(double x, double y, CodeDrawImage image)
      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

      public void drawImage(double x, double y, double width, double height, CodeDrawImage image)
      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. See Interpolation.
    • clear

      public void clear()
      Colors the whole canvas in white.
    • clear

      public void clear(Color color)
      Colors the whole canvas in the color given as a parameter.
      Parameters:
      color - The color the canvas will be colored in.
    • copyTo

      public void copyTo(Graphics target, Interpolation interpolation)
      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. See Interpolation.
    • convertToBufferedImage

      public BufferedImage convertToBufferedImage()
      Creates a copy of this CodeDrawImage in the form of a BufferedImage.
      Returns:
      a BufferedImage.