Image - CoolPotato31F/Java-Graphics GitHub Wiki
Image Class
Overview
The Image class represents an image that can be drawn onto a graphical window. It supports resizing, scaling, alignment, rotation, and outlining.
Attributes
-
private Point position
The position of the image in the graphical window. -
private int width, height
The dimensions of the image. -
private BufferedImage image
The buffered image to be rendered. -
private GraphWin canvas
The graphical window where the image is drawn. -
private Color outlineColor
The color of the image's outline (default:null). -
private int outlineWidth
The width of the outline (default:1). -
private String alignment
The alignment of the image:"top-left","top-right","bottom-left","bottom-right", or"center"(default:"center"). -
private double rotation
The rotation angle of the image in degrees (default:0). -
private BufferedImage original
A copy of the original image before any transformations. -
private double scale
The scale factor of the image.
Constructors
Image(Point position, String filePath)
Constructs an Image object from a file path with a specified position.
Parameters:
position- The position of the image as aPointobject.filePath- The file path to the image.
Image(Point position, URL filePath)
Constructs an Image object from a URL with a specified position.
Parameters:
position- The position of the image as aPointobject.filePath- The URL pointing to the image file.
Methods
void setOutline(Color color)
Sets the outline color of the image.
Parameters:
color- The outline color.
void setOutlineWidth(int width)
Sets the width of the image's outline.
Parameters:
width- The outline width.
void move(double dx, double dy)
Moves the image by the given offsets.
Parameters:
dx- The change in the x position.dy- The change in the y position.
void setSize(int width, int height)
Sets the size of the image.
Parameters:
width- The new width of the image.height- The new height of the image.
void setScale(double scaleFactor)
Scales the image by a given factor.
Parameters:
scaleFactor- The scale factor (e.g.,2.0doubles the size,0.5halves it).
void setAlignment(String alignment)
Sets the alignment of the image.
Parameters:
alignment- The alignment of the image ("top-left","top-right","bottom-left","bottom-right","center").
void rotate(double angle)
Rotates the image by the given angle in degrees.
Parameters:
angle- The angle in degrees.
void draw(GraphWin canvas)
Draws the image onto a GraphWin canvas.
Parameters:
canvas- TheGraphWininstance where the image will be drawn.
void undraw()
Removes the image from the graphical window.
void drawPanel(Graphics2D graphics)
Renders the image onto a Graphics2D panel, including alignment and outline.
Parameters:
graphics- TheGraphics2Dobject used for rendering.