Class Picture

java.lang.Object
  extended by Picture
All Implemented Interfaces:
Shape

public class Picture
extends Object
implements Shape

A picture from an image file.


Constructor Summary
Picture()
          Constructs a picture with no image.
Picture(double width, double height)
          Constructs a picture with a given width and height.
Picture(String source)
          Constructs an image 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 getHeight()
          Gets the height of this picture.
 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(String source)
          Loads a new image from a given file or URL.
 void paintShape(Graphics2D g2)
          Draws this shape.
 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.
 void translate(double dx, double dy)
          Moves this picture by a given amount.
 
Methods inherited from class
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Picture

public Picture()
Constructs a picture with no image.


Picture

public Picture(double width,
               double height)
Constructs a picture with a given width and height.

Parameters:
width - the desired width
height - the desired height

Picture

public Picture(String source)
Constructs an image from a given file or URL.

Parameters:
source - the filename or URL
Method Detail

draw

public void draw()
Shows this picture on the canvas.


getColorAt

public Color getColorAt(int i)
Gets the color of a pixel.

Parameters:
i - the pixel index
Returns:
the color at pixel i

getColorAt

public Color getColorAt(int x,
                        int y)
Gets the color of a pixel.

Parameters:
x - the x-coordinate (column) of the pixel
y - the y-coordinate (row) of the pixel
color - the new color for the pixel

getHeight

public int getHeight()
Gets the height of this picture.

Specified by:
getHeight in interface Shape
Returns:
the height

getWidth

public int getWidth()
Gets the width of this picture.

Specified by:
getWidth in interface Shape
Returns:
the width

getX

public int getX()
Gets the leftmost x-position of the shape.

Specified by:
getX in interface Shape
Returns:
the leftmost x-position

getY

public int getY()
Gets the topmost y-position of the shape.

Specified by:
getY in interface Shape
Returns:
the topmost y-position

grow

public void grow(double dw,
                 double dh)
Resizes this picture both horizontally and vertically.

Parameters:
dw - the amount by which to resize the width on each side
dw - the amount by which to resize the height on each side

load

public void load(String source)
Loads a new image from a given file or URL.

Parameters:
source - the filename or URL

paintShape

public void paintShape(Graphics2D g2)
Draws this shape.

Specified by:
paintShape in interface Shape
Parameters:
g2 - the graphics context

pixels

public int pixels()
The number of pixels in this picture.

Returns:
the number of pixels

setColorAt

public void setColorAt(int i,
                       Color color)
Sets the color of a pixel.

Parameters:
i - the pixel index
color - the new color for the pixel

setColorAt

public void setColorAt(int x,
                       int y,
                       Color color)
Sets the color of a pixel.

Parameters:
x - the x-coordinate (column) of the pixel
y - the y-coordinate (row) of the pixel
the - color of the pixel at the given row and column

translate

public void translate(double dx,
                      double dy)
Moves this picture by a given amount.

Parameters:
dx - the amount by which to move in x-direction
dy - the amount by which to move in y-direction