public final class Picture extends Object implements ActionListener
Pixel (x, y) is column x and row y. By default, the origin (0, 0) is upper left, which is a common convention in image processing. The method setOriginLowerLeft() change the origin to the lower left.
For additional documentation, see Section 3.1 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
Constructor and Description |
---|
Picture(File file)
Initializes a picture by reading in a .png, .gif, or .jpg from a File.
|
Picture(int w,
int h)
Initializes a blank w-by-h picture, where each pixel is
black.
|
Picture(Picture pic)
Initializes a new picture that is a deep copy of pic.
|
Picture(String filename)
Initializes a picture by reading in a .png, .gif, or .jpg from the given
filename or URL name.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Opens a save dialog box when the user selects "Save As" from the menu.
|
boolean |
equals(Object obj)
Is this Picture equal to obj?
|
Color |
get(int x,
int y)
Returns the color of pixel (x, y).
|
JLabel |
getJLabel()
Returns a JLabel containing this picture, for embedding in a JPanel, JFrame
or other GUI widget.
|
int |
height()
Returns the height of the picture (in pixels).
|
static void |
main(String[] args)
Tests this Picture data type.
|
void |
save(File file)
Saves the picture to a file in a standard image format.
|
void |
save(String name)
Saves the picture to a file in a standard image format.
|
void |
set(int x,
int y,
Color color)
Sets the color of pixel (x, y) to given color.
|
void |
setOriginLowerLeft()
Sets the origin to be the lower left pixel.
|
void |
setOriginUpperLeft()
Sets the origin to be the upper left pixel.
|
void |
show()
Displays the picture in a window on the screen.
|
int |
width()
Returns the width of the picture (in pixels).
|
public Picture(int w, int h)
public Picture(Picture pic)
public Picture(String filename)
public Picture(File file)
public JLabel getJLabel()
public void setOriginUpperLeft()
public void setOriginLowerLeft()
public void show()
public int height()
public int width()
public Color get(int x, int y)
public void set(int x, int y, Color color)
public boolean equals(Object obj)
public void save(String name)
public void save(File file)
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
public static void main(String[] args)