java.lang.ObjectPicture
public class Picture
A picture from an image file.
Nested Class Summary | |
---|---|
(package private) static class |
Picture.Canvas
|
Constructor Summary | |
---|---|
Picture()
Constructs a picture with no image. |
|
Picture(double width,
double height)
Constructs a picture with a given width and height. |
|
Picture(int[][] grayLevels)
|
|
Picture(java.lang.String source)
Constructs a picture from a given file or URL. |
Method Summary | |
---|---|
void |
draw()
Shows this picture on the canvas. |
Color |
getColorAt(int i)
Gets the color of a pixel. |
Color |
getColorAt(int x,
int y)
Gets the color of a pixel. |
int[][] |
getGrayLevels()
|
int |
getHeight()
Gets the height of this picture. |
int |
getMaxX()
Gets the rightmost x-position of the shape. |
int |
getMaxY()
Gets the bottommost y-position of the shape. |
int |
getWidth()
Gets the width of this picture. |
int |
getX()
Gets the leftmost x-position of the shape. |
int |
getY()
Gets the topmost y-position of the shape. |
void |
grow(double dw,
double dh)
Resizes this picture both horizontally and vertically. |
void |
load(java.lang.String source)
Loads a new image from a given file or URL. |
void |
paintShape(java.awt.Graphics2D g2)
Draws this shape. |
void |
pause()
Pauses so that one can look at the picture. |
void |
pick()
Displays a file chooser for picking a file, loads the picture from the file that the user selected, and pauses so that the user can see the loaded picture. |
int |
pixels()
The number of pixels in this picture. |
void |
setColorAt(int i,
Color color)
Sets the color of a pixel. |
void |
setColorAt(int x,
int y,
Color color)
Sets the color of a pixel. |
java.lang.String |
toString()
|
void |
translate(double dx,
double dy)
Moves this picture by a given amount. |
Methods inherited from class |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Picture()
public Picture(double width, double height)
width
- the desired widthheight
- the desired heightpublic Picture(int[][] grayLevels)
public Picture(java.lang.String source)
source
- the filename or URLMethod Detail |
---|
public void draw()
public Color getColorAt(int i)
i
- the pixel index
public Color getColorAt(int x, int y)
x
- the x-coordinate (column) of the pixely
- the y-coordinate (row) of the pixelcolor
- the new color for the pixelpublic int[][] getGrayLevels()
public int getHeight()
public int getMaxX()
public int getMaxY()
public int getWidth()
public int getX()
public int getY()
public void grow(double dw, double dh)
dw
- the amount by which to resize the width on each sidedw
- the amount by which to resize the height on each sidepublic void load(java.lang.String source)
source
- the filename or URLpublic void paintShape(java.awt.Graphics2D g2)
g2
- the graphics contextpublic void pause()
public void pick()
public int pixels()
public void setColorAt(int i, Color color)
i
- the pixel indexcolor
- the new color for the pixelpublic void setColorAt(int x, int y, Color color)
x
- the x-coordinate (column) of the pixely
- the y-coordinate (row) of the pixelthe
- color of the pixel at the given row and columnpublic java.lang.String toString()
toString
in class java.lang.Object
public void translate(double dx, double dy)
dx
- the amount by which to move in x-directiondy
- the amount by which to move in y-direction