Package seamcarving
Class Picture
- java.lang.Object
-
- seamcarving.Picture
-
public class Picture extends Object
A digital picture represented as red-green-blue colorint
pixels.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) BufferedImage
image
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
Picture()
Constructs a null picture for subclassing purposes.Picture(int width, int height)
Constructs an empty picture with the given width and height dimensions.private
Picture(BufferedImage image)
Constructs a picture from the given image.Picture(File file)
Constructs a picture from the given file.Picture(Picture other)
Constructs a copy of the given picture.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
get(int x, int y)
Returns the 24-bit red-green-blue (RGB) color for the pixel (x, y).int
height()
Returns the height of the picture.static Picture
random(int width, int height)
Returns a new picture with the given width and height dimensions filled with randomly-generated colors.void
save(File file)
Writes the picture to the given file path.void
set(int x, int y, int rgb)
Reassigns the 24-bit red-green-blue (RGB) color for the pixel (x, y).int
width()
Returns the width of the picture.
-
-
-
Field Detail
-
image
final BufferedImage image
-
-
Constructor Detail
-
Picture
Picture()
Constructs a null picture for subclassing purposes.
-
Picture
private Picture(BufferedImage image)
Constructs a picture from the given image.- Parameters:
image
- the input image.
-
Picture
public Picture(int width, int height)
Constructs an empty picture with the given width and height dimensions.- Parameters:
width
- the horizontal dimension for the picture.height
- the vertical dimension for the picture.
-
Picture
public Picture(Picture other)
Constructs a copy of the given picture.- Parameters:
other
- the input picture.
-
Picture
public Picture(File file) throws IOException
Constructs a picture from the given file.- Parameters:
file
- the input file.- Throws:
IOException
- if an error occurs during reading.
-
-
Method Detail
-
random
public static Picture random(int width, int height)
Returns a new picture with the given width and height dimensions filled with randomly-generated colors.- Parameters:
width
- the horizontal dimension for the picture.height
- the vertical dimension for the picture.- Returns:
- a new picture with the given width and height dimensions filled with randomly-generated colors.
-
get
public int get(int x, int y)
Returns the 24-bit red-green-blue (RGB) color for the pixel (x, y).- Parameters:
x
- the x-index into the picture.y
- the y-index into the picture.- Returns:
- the 24-bit red-green-blue (RGB) color for the pixel (x, y).
-
set
public void set(int x, int y, int rgb)
Reassigns the 24-bit red-green-blue (RGB) color for the pixel (x, y).- Parameters:
x
- the x-index into the picture.y
- the y-index into the picture.rgb
- the 24-bit red-green-blue (RGB) color for the pixel (x, y).
-
width
public int width()
Returns the width of the picture.- Returns:
- the width of the picture.
-
height
public int height()
Returns the height of the picture.- Returns:
- the height of the picture.
-
save
public void save(File file) throws IOException
Writes the picture to the given file path.- Parameters:
file
- the file path.- Throws:
IOException
- if an error occurs during writing.
-
-