Class Picture

java.lang.Object
  extended by Picture

public class Picture
extends Object

The Picture class stores a two-dimensional image. This Picture is comprised of pixels (see Pixel) and is displayed on-screen through the use of a PictureFrame.

Author:
Richard Wicentowski

Constructor Summary
Picture(int width, int height)
          Create a Picture with the specified width and height.
Picture(Picture source)
          Create a Picture by copying the contents of another (non-null) Picture.
Picture(String filename)
          Create a Picture from a file.
 
Method Summary
 BufferedImage getBufferedImage()
          Returns the BufferedImage underlying the Picture.
 int getHeight()
          Return the height of the Picture.
 Pixel getPixel(int x, int y)
          Return the Pixel stored at this location.
 int getWidth()
          Return the width of the Picture.
 Pixel setPixel(int x, int y, Pixel pixel)
          Set the location (x, y) to a new Pixel value.
 void updateImage()
          Flush changes to the underlying image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Picture

public Picture(int width,
               int height)
Create a Picture with the specified width and height.

Parameters:
width - the width (> 0) of the picture.
height - the height (> 0) of the picture.

Picture

public Picture(String filename)
Create a Picture from a file.

Parameters:
filename - the name of the image file.

Picture

public Picture(Picture source)
Create a Picture by copying the contents of another (non-null) Picture.

Parameters:
source - the Picture to copy.
Method Detail

getWidth

public int getWidth()
Return the width of the Picture.

Returns:
the width of the Picture.

getHeight

public int getHeight()
Return the height of the Picture.

Returns:
the height of the Picture.

getBufferedImage

public BufferedImage getBufferedImage()
Returns the BufferedImage underlying the Picture. The PictureFrame needs access to the BufferedImage in order to display its contents on the frame. You will not need to use this function.

Returns:
the BufferedImage underlying the Picture.

updateImage

public void updateImage()
Flush changes to the underlying image. To make the Picture class more efficient, changes to the underlying image are not made every time a Pixel is changed. The updateImage method forces the underlying image to be updated. Note that calling this method does not update the on-screen image (see PictureFrame.refresh(Picture)).


getPixel

public Pixel getPixel(int x,
                      int y)
Return the Pixel stored at this location. The top-left corner of the image is coordinate (0, 0).

Parameters:
x - the x-coordinate of the Pixel to get.
y - the y-coordinate of the Pixel to get.

setPixel

public Pixel setPixel(int x,
                      int y,
                      Pixel pixel)
Set the location (x, y) to a new Pixel value. Returns the Pixel previously stored at this location. The top-left corner of the image is coordinate (0, 0).

Parameters:
x - the x-coordinate of the Pixel to set.
y - the y-coordinate of the Pixel to set.
pixel - the Pixel value to put at this coordinate.
Returns:
the previous Pixel at this location.