Package stdlib
Class Picture
java.lang.Object
stdlib.Picture
- All Implemented Interfaces:
ActionListener
,EventListener
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.
By default, pixel (x, y) is column x, row y, where (0, 0) is upper left. 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.
-
Field Summary
Modifier and TypeFieldDescriptionprivate String
private JFrame
private final int
private BufferedImage
private boolean
private final int
-
Constructor Summary
ConstructorDescriptionPicture
(int w, int h) Create a blank w-by-h picture, where each pixel is black.Create a picture by reading in a .png, .gif, or .jpg from a File.Create a picture by reading in a .png, .gif, or .jpg from the given filename or URL name.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Opens a save dialog box when the user selects "Save As" from the menu.boolean
Is this Picture equal to obj?get
(int i, int j) Return the color of pixel (i, j).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
Test client.void
Save the picture to a file in a standard image format.void
Save the picture to a file in a standard image format.void
Set the color of pixel (i, j) to c.void
Set the origin to be the lower left pixel.void
Set the origin to be the upper left pixel.void
show()
Display the picture in a window on the screen.int
width()
Return the width of the picture in pixels.
-
Field Details
-
image
-
frame
-
filename
-
isOriginUpperLeft
-
width
-
height
-
-
Constructor Details
-
Picture
Create a blank w-by-h picture, where each pixel is black. -
Picture
Copy constructor. -
Picture
Create a picture by reading in a .png, .gif, or .jpg from the given filename or URL name. -
Picture
Create a picture by reading in a .png, .gif, or .jpg from a File.
-
-
Method Details
-
getJLabel
Return a JLabel containing this Picture, for embedding in a JPanel, JFrame or other GUI widget. -
setOriginUpperLeft
Set the origin to be the upper left pixel. -
setOriginLowerLeft
Set the origin to be the lower left pixel. -
show
Display the picture in a window on the screen. -
height
Return the height of the picture in pixels. -
width
Return the width of the picture in pixels. -
get
Return the color of pixel (i, j). -
set
Set the color of pixel (i, j) to c. -
equals
Is this Picture equal to obj? -
save
Save the picture to a file in a standard image format. The filetype must be .png or .jpg. -
save
Save the picture to a file in a standard image format. -
actionPerformed
Opens a save dialog box when the user selects "Save As" from the menu.- Specified by:
actionPerformed
in interfaceActionListener
-
main
Test client. Reads a picture specified by the command-line argument, and shows it in a window on the screen.
-