ObjectPicture
public final class Picture
This class provides methods for manipulating individual pixels of an image. The original image can be read from a file in JPEG, GIF, or PNG format, or the user can create a blank image of a given size. This class includes methods for displaying the image in a window on the screen or saving to a file.
Pixel (x, y) is column x, row y, where (0, 0) is upper left.
For additional documentation, see Section 3.1 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
| Constructor Summary | |
|---|---|
Picture(java.io.File file)
Create a picture by reading in a .png, .gif, or .jpg from a File. |
|
Picture(int w,
int h)
Create an empty w-by-h picture. |
|
Picture(String filename)
Create a picture by reading in a .png, .gif, or .jpg from the given filename or URL name. |
|
| Method Summary | |
|---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Opens a save dialog box when the user selects "Save As" from the menu. |
java.awt.Color |
get(int i,
int j)
Return the Color of pixel (i, j). |
javax.swing.JLabel |
getJLabel()
Return a JLabel containing this Picture, for embedding in a JPanel, JFrame or other GUI widget. |
int |
height()
Return the height of the picture (in pixels). |
static void |
main(String[] args)
Test client. |
void |
save(java.io.File file)
Save the picture to a file in a standard image format. |
void |
save(String name)
Save the picture to a file in a standard image format. |
void |
set(int i,
int j,
java.awt.Color c)
Set the Color of pixel (i, j) to c. |
void |
show()
Display the picture in a window on the screen. |
int |
width()
Return the width of the picture (in pixels). |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Picture(int w,
int h)
public Picture(String filename)
public Picture(java.io.File file)
| Method Detail |
|---|
public javax.swing.JLabel getJLabel()
public void show()
public int height()
public int width()
public java.awt.Color get(int i,
int j)
public void set(int i,
int j,
java.awt.Color c)
public void save(String name)
public void save(java.io.File file)
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed in interface java.awt.event.ActionListenerpublic static void main(String[] args)