Package doodlepad

Class Image


public class Image extends Shape
A class that loads an image from a file and draws it on a Pad.
  • Constructor Details

    • Image

      public Image(String path, double x, double y)
      Constructor for objects of class Image
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
    • Image

      public Image(String path, double x, double y, Pad pad)
      Constructor for objects of class Image
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      pad - The Pad to which the Image should be added.
    • Image

      public Image(String path, double x, double y, Layer layer)
      Constructor for objects of class Image
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      layer - The Layer object to which the Image should be added, or null if not to add to a Layer.
    • Image

      public Image(String path, double x, double y, double width, double height)
      Constructor for objects of class Image
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      width - The width with which to draw the image.
      height - The height with which to draw the image.
    • Image

      public Image(String path, double x, double y, double width, double height, Pad pad)
      Constructor for objects of class Image
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      width - The width with which to draw the image.
      height - The height with which to draw the image.
      pad - The Pad to which this Image should be added.
    • Image

      public Image(String path, double x, double y, double width, double height, Layer layer)
      Constructor for objects of class Image
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      width - The width with which to draw the image.
      height - The height with which to draw the image.
      layer - The Layer object to which the Image should be added, or null if not to add to a Pad.
    • Image

      public Image(double x, double y, double width, double height)
      Constructor for creating an empty image
      Parameters:
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      width - The width with which to draw the image.
      height - The height with which to draw the image.
  • Method Details

    • save

      public boolean save(String path)
      Save an Image to the given file path as type. Note: JPG files are not supported because that format does not have an alpha channel.
      Parameters:
      path - Full path to where new file is to be saved. Must include file extension png or tiff
      Returns:
      true if successful, false otherwise
    • setPixel

      public void setPixel(int x, int y, int red, int green, int blue)
      Set the color of the pixel at coordinates (x, y)
      Parameters:
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      red - The red component of the pixel color [0, 255]
      green - The green component of the pixel color [0, 255]
      blue - The blue component of the pixel color [0, 255]
    • setPixel

      public void setPixel(int x, int y, Color clr)
      Set the color of the pixel at coordinates (x, y)
      Parameters:
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      clr - The Color object to use to assign pixel color.
    • setPixel

      public void setPixel(int x, int y, int gray)
      Set the color of the pixel at coordinates (x, y)
      Parameters:
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      gray - The gray level of the pixel color [0, 255]
    • getPixel

      public Color getPixel(int x, int y)
      Get the pixel color as a Color object.
      Parameters:
      x - x-coordinate of the pixel.
      y - y-coordinate of the pixel.
      Returns:
      A Color object encapsulating the pixel color.
    • getRed

      public int getRed(int x, int y)
      Get red component of pixel color.
      Parameters:
      x - x-coordinate of the pixel.
      y - y-coordinate of the pixel.
      Returns:
      pixel red component as an integer in range [0, 255].
    • getGreen

      public int getGreen(int x, int y)
      Get green component of pixel color.
      Parameters:
      x - x-coordinate of the pixel.
      y - y-coordinate of the pixel.
      Returns:
      pixel green component as an integer in range [0, 255].
    • getBlue

      public int getBlue(int x, int y)
      Get blue component of pixel color.
      Parameters:
      x - x-coordinate of the pixel.
      y - y-coordinate of the pixel.
      Returns:
      pixel blue component as an integer in range [0, 255].
    • getAlpha

      public int getAlpha(int x, int y)
      Get alpha component of pixel color.
      Parameters:
      x - x-coordinate of the pixel.
      y - y-coordinate of the pixel.
      Returns:
      pixel alpha component as an integer in range [0, 255].
    • setBackground

      public void setBackground(double red, double green, double blue)
      Set the background color for the Image
      Parameters:
      red - The background color red component
      green - The background color green component
      blue - The background color blue component
    • setBackground

      public void setBackground(double gray)
      Set the background color for the Image to a gray value
      Parameters:
      gray - The background gray scale
    • drawArc

      public void drawArc(double x, double y, double width, double height, double startAngle, double arcAngle)
      Draws an arc on the Image. The arc is defined by a section of an ellipse bounded by the rectangle with upper left corner at (x, y) and size (width, height). The section starts at angle startAngle (degrees) and extends by arcAngle (degrees).
      Parameters:
      x - The upper x-coordinate of the arc`s related ellipse bounding box (pixels).
      y - The upper y-coordinate of the arc`s related ellipse bounding box (pixels).
      width - The width of the arc`s related ellipse (pixels).
      height - The height of the arc`s related ellipse bounding box (pixels).
      startAngle - The starting angle at which to begin drawing the arc (degrees).
      arcAngle - The angular extent of the arc, which defines its length (degrees).
    • drawOval

      public void drawOval(double x, double y, double width, double height)
      Draw an oval on the Image.
      Parameters:
      x - The x-coordinate of the upper left-hand corner of the oval.
      y - The y-coordinate of the upper left-hand corner of the oval.
      width - The width of the oval.
      height - The height of the oval.
    • drawRectangle

      public void drawRectangle(double x, double y, double width, double height)
      Draw a rectangle on the Image.
      Parameters:
      x - The x-coordinate of the upper left-hand corner of the rectangle.
      y - The y-coordinate of the upper left-hand corner of the rectangle.
      width - The width of the rectangle.
      height - The height of the rectangle.
    • drawLine

      public void drawLine(double x1, double y1, double x2, double y2)
      Draw a line on the Image.
      Parameters:
      x1 - The x-coordinate of the line's first point.
      y1 - The y-coordinate of the line's first point.
      x2 - The x-coordinate of the line's second point.
      y2 - The y-coordinate of the line's second point.
    • drawRoundRect

      public void drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
      Draw a rounded rectangle on the Image.
      Parameters:
      x - The x-coordinate of the upper left corner of the rounded rectangle.
      y - The y-coordinate of the upper left corner of the rounded rectangle.
      width - The width of the rounded rectangle.
      height - The height of the rounded rectangle.
      arcWidth - The width of the arc that forms a corner of the rounded rectangle.
      arcHeight - The height of the arc that forms a corner of the rounded rectangle.
    • drawPolygon

      public void drawPolygon(List<Point> points)
      Draw a polygon on the Image
      Parameters:
      points - List of Point objects that define coordinate points of polygon
    • drawPolygon

      public void drawPolygon(double[] xPoints, double[] yPoints)
      Draw a polygon on the Image
      Parameters:
      xPoints - The array of x-coordinates for all polygon points.
      yPoints - The array of y-coordinates for all polygon points.
    • drawText

      public void drawText(String text, double x, double y, int size, int style, String fontName)
      Draw text on the Image.
      Parameters:
      text - The String drawn as the Text object
      x - The x-coordinate of the Text object upper left corner.
      y - The y-coordinate of the Text object upper left corner.
      size - The font size used to draw the Text object.
      style - The Font class constant that defines the style used to draw the Text object. Example: Font.PLAIN
      fontName - The name of the font used to draw the Text object, Example: "Arial"
    • drawText

      public void drawText(String text, double x, double y, int size, String fontName)
      Draw text on an Image with some default font attributes.
      Parameters:
      text - The String drawn as the Text object
      x - The x-coordinate of the Text object upper left corner.
      y - The y-coordinate of the Text object upper left corner.
      size - The font size used to draw the Text object.
      fontName - The name of the font used to draw the Text object, Example: "Arial"
    • drawText

      public void drawText(String text, double x, double y, String fontName)
      Draw text on an Image with some default font attributes.
      Parameters:
      text - The String drawn as the Text object
      x - The x-coordinate of the Text object upper left corner.
      y - The y-coordinate of the Text object upper left corner.
      fontName - The name of the font used to draw the Text object, Example: "Arial"
    • drawText

      public void drawText(String text, double x, double y, int size, int style)
      Draw text on an Image with some default font attributes.
      Parameters:
      text - The String drawn as the Text object
      x - The x-coordinate of the Text object upper left corner.
      y - The y-coordinate of the Text object upper left corner.
      size - The font size used to draw the Text object.
      style - The Font class constant that defines the style used to draw the Text object. Example: Font.PLAIN
    • drawText

      public void drawText(String text, double x, double y, int size)
      Draw text on an Image with some default font attributes.
      Parameters:
      text - The String drawn as the Text object
      x - The x-coordinate of the Text object upper left corner.
      y - The y-coordinate of the Text object upper left corner.
      size - The font size used to draw the Text object.
    • drawText

      public void drawText(String text, double x, double y)
      Draw text on an Image with the default font attributes.
      Parameters:
      text - The String drawn as the Text object
      x - The x-coordinate of the Text object upper left corner.
      y - The y-coordinate of the Text object upper left corner.
    • setText

      public void setText(String text)
      A no-op to prevent setting text for this Shape.
      Overrides:
      setText in class Shape
      Parameters:
      text - The internal text as a String
    • toString

      public String toString()
      Generate a representation of the Image object.
      Overrides:
      toString in class Shape
      Returns:
      String representation
    • draw

      public void draw(Graphics2D g)
      Draw the shape
      Specified by:
      draw in class Shape
      Parameters:
      g - The Graphics2D object on which to draw the image