Package doodlepad
Class Image
java.lang.Object
doodlepad.Shape
doodlepad.Image
A class that loads an image from a file and draws it on a Pad.
-
Nested Class Summary
Nested classes/interfaces inherited from class doodlepad.Shape
Shape.ShapeMouseEventHandler, Shape.ShapeSelectionEventHandler
-
Field Summary
Fields inherited from class doodlepad.Shape
draggable, eventsEnabled, fillColor, filled, font, fontFamily, fontSize, fontStyle, height, layer, selectable, selected, shapeListener, strokeColor, stroked, strokeWidth, text, textFillColor, transform, visible, width, x, y
-
Constructor Summary
ConstructorDescriptionImage
(double x, double y, double width, double height) Constructor for creating an empty imageConstructor for objects of class ImageConstructor for objects of class ImageConstructor for objects of class ImageConstructor for objects of class ImageConstructor for objects of class ImageConstructor for objects of class Image -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(Graphics2D g) Draw the shapevoid
drawArc
(double x, double y, double width, double height, double startAngle, double arcAngle) Draws an arc on the Image.void
drawLine
(double x1, double y1, double x2, double y2) Draw a line on the Image.void
drawOval
(double x, double y, double width, double height) Draw an oval on the Image.void
drawPolygon
(double[] xPoints, double[] yPoints) Draw a polygon on the Imagevoid
drawPolygon
(List<Point> points) Draw a polygon on the Imagevoid
drawRectangle
(double x, double y, double width, double height) Draw a rectangle on the Image.void
drawRoundRect
(double x, double y, double width, double height, double arcWidth, double arcHeight) Draw a rounded rectangle on the Image.void
Draw text on an Image with the default font attributes.void
Draw text on an Image with some default font attributes.void
Draw text on an Image with some default font attributes.void
Draw text on the Image.void
Draw text on an Image with some default font attributes.void
Draw text on an Image with some default font attributes.int
getAlpha
(int x, int y) Get alpha component of pixel color.int
getBlue
(int x, int y) Get blue component of pixel color.int
getGreen
(int x, int y) Get green component of pixel color.getPixel
(int x, int y) Get the pixel color as a Color object.int
getRed
(int x, int y) Get red component of pixel color.boolean
Save an Image to the given file path as type.void
setBackground
(double gray) Set the background color for the Image to a gray valuevoid
setBackground
(double red, double green, double blue) Set the background color for the Imagevoid
setPixel
(int x, int y, int gray) Set the color of the pixel at coordinates (x, y)void
setPixel
(int x, int y, int red, int green, int blue) Set the color of the pixel at coordinates (x, y)void
Set the color of the pixel at coordinates (x, y)void
A no-op to prevent setting text for this Shape.toString()
Generate a representation of the Image object.Methods inherited from class doodlepad.Shape
contains, contains, drawText, getArea, getCenter, getDraggable, getEventsEnabled, getFillAlpha, getFillBlue, getFillColor, getFilled, getFillGreen, getFillRed, getFontFamily, getFontSize, getFontStyle, getHeight, getLayer, getLocation, getPad, getPadLocation, getSelectable, getSelected, getSize, getStrokeAlpha, getStrokeBlue, getStrokeColor, getStroked, getStrokeGreen, getStrokeRed, getStrokeWidth, getText, getTransform, getVisible, getWidth, getWindowLocation, getX, getY, intersects, move, onMouseClicked, onMouseDoubleClicked, onMouseDragged, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onSelectionChanged, repaint, reset, rotate, rotate, scale, scale, scale, scale, setCenter, setCenter, setDraggable, setEventsEnabled, setFillColor, setFillColor, setFillColor, setFillColor, setFilled, setFontFamily, setFontSize, setFontStyle, setHeight, setLocation, setLocation, setMouseClickedHandler, setMouseDoubleClickedHandler, setMouseDraggedHandler, setMouseEnteredHandler, setMouseExitedHandler, setMouseMovedHandler, setMousePressedHandler, setMouseReleasedHandler, setPadLocation, setSelectable, setSelected, setSelectionChangedHandler, setSize, setSize, setStrokeColor, setStrokeColor, setStrokeColor, setStrokeColor, setStroked, setStrokeWidth, setTextColor, setTextColor, setTextColor, setTextColor, setTransform, setVisible, setWidth, setWindowLocation, setX, setY, toBack, toFront, toWindowCoords, toWindowCoords, translate
-
Constructor Details
-
Image
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
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
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
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
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
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
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
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
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 componentgreen
- The background color green componentblue
- 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
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
Draw text on the Image.- Parameters:
text
- The String drawn as the Text objectx
- 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.PLAINfontName
- The name of the font used to draw the Text object, Example: "Arial"
-
drawText
Draw text on an Image with some default font attributes.- Parameters:
text
- The String drawn as the Text objectx
- 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
Draw text on an Image with some default font attributes.- Parameters:
text
- The String drawn as the Text objectx
- 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
Draw text on an Image with some default font attributes.- Parameters:
text
- The String drawn as the Text objectx
- 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
Draw text on an Image with some default font attributes.- Parameters:
text
- The String drawn as the Text objectx
- 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
Draw text on an Image with the default font attributes.- Parameters:
text
- The String drawn as the Text objectx
- The x-coordinate of the Text object upper left corner.y
- The y-coordinate of the Text object upper left corner.
-
setText
A no-op to prevent setting text for this Shape. -
toString
Generate a representation of the Image object. -
draw
Draw the shape
-