Class SimplePicture
java.lang.Object
SimplePicture
- All Implemented Interfaces:
DigitalPicture
- Direct Known Subclasses:
Picture
A class that represents a simple picture. A simple picture may have
an associated file name and a title. A simple picture has pixels,
width, and height. A simple picture uses a BufferedImage to
hold the pixels. You can show a simple picture in a
PictureFrame (a JFrame).
Copyright Georgia Institute of Technology 2004
-
Constructor Summary
ConstructorsConstructorDescriptionA Constructor that takes no arguments.SimplePicture
(int width, int height) A Constructor that takes a file name and uses the file to create a pictureSimplePicture
(int width, int height, Color theColor) A constructor that takes the width and height desired for a picture and creates a buffered image of that size.SimplePicture
(BufferedImage image) A constructor that takes a buffered imageSimplePicture
(SimplePicture copyPicture) A Constructor that takes a picture to copy information from -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMessage
(String message, int xPos, int yPos) Method to write the contents of the picture to a file with the passed name without throwing errorsvoid
copyPicture
(SimplePicture sourcePicture) Method that will copy all of the passed source picture into the current picture objectMethod to get a Graphics2D object for this picture which can be used to do 2D drawing on the picturevoid
drawString
(String text, int xPos, int yPos) Method to draw a string at the given location on the pictureint
getBasicPixel
(int x, int y) Method to return the pixel value as an int for the given x and y locationMethod to get the buffered imageMethod to get the extension for this pictureMethod to get the file name associated with the pictureMethod to get a graphics object for this picture to use to draw onint
Method to get the height of the picture in pixelsgetImage()
Method to get an image from the pictureMethod to get the picture frame for the picturegetPictureWithHeight
(int height) Method to create a new picture of the passed height.getPictureWithWidth
(int width) Method to create a new picture of the passed width.getPixel
(int x, int y) Method to get a pixel object for the given x and y locationPixel[]
Method to get a one-dimensional array of Pixels for this simple picturegetTitle()
Method to get the title of the pictureMethod to get the coordinates of the enclosing rectangle after this transformation is applied to the current pictureMethod to get the coordinates of the enclosing rectangle after this transformation is applied to the current pictureint
getWidth()
Method to get the width of the picture in pixelsvoid
hide()
Method to hide the picturevoid
Method to load the buffered image with the passed imagevoid
repaint()
Method to open a picture explorer on a copy of this simple picturescale
(double xFactor, double yFactor) Method to create a new picture by scaling the current picture by the given x and y factorsvoid
setAllPixelsToAColor
(Color color) Method to set the color in the picture to the passed colorvoid
setBasicPixel
(int x, int y, int rgb) Method to set the value of a pixel in the picture from an intvoid
setFileName
(String name) Method to set the file namevoid
setPictureFrame
(PictureFrame pictureFrame) Method to set the picture frame for this picturevoid
Method to set the title for the picturevoid
setVisible
(boolean flag) Method to make this picture visible or notvoid
show()
Method to show the picture in a picture frametoString()
Method to return a string with information about this picture
-
Constructor Details
-
SimplePicture
public SimplePicture()A Constructor that takes no arguments. All fields will be null. A no-argument constructor must be given in order for a class to be able to be subclassed. By default all subclasses will implicitly call this in their parent's no argument constructor unless a different call to super() is explicitly made as the first line of code in a constructor. -
SimplePicture
public SimplePicture(int width, int height) A Constructor that takes a file name and uses the file to create a picture- Parameters:
fileName
- the file name to use in creating the picture
-
SimplePicture
A constructor that takes the width and height desired for a picture and creates a buffered image of that size. It also takes the color to use for the background of the picture.- Parameters:
width
- the desired widthheight
- the desired heighttheColor
- the background color for the picture
-
SimplePicture
A Constructor that takes a picture to copy information from- Parameters:
copyPicture
- the picture to copy from
-
SimplePicture
A constructor that takes a buffered image- Parameters:
image
- the buffered image
-
-
Method Details
-
getExtension
Method to get the extension for this picture- Returns:
- the extendsion (jpg or bmp)
-
copyPicture
Method that will copy all of the passed source picture into the current picture object- Parameters:
sourcePicture
- the picture object to copy
-
setAllPixelsToAColor
Method to set the color in the picture to the passed color- Parameters:
color
- the color to set to
-
getBufferedImage
Method to get the buffered image- Specified by:
getBufferedImage
in interfaceDigitalPicture
- Returns:
- the buffered image
-
getGraphics
Method to get a graphics object for this picture to use to draw on- Returns:
- a graphics object to use for drawing
-
createGraphics
Method to get a Graphics2D object for this picture which can be used to do 2D drawing on the picture -
getFileName
Method to get the file name associated with the picture- Specified by:
getFileName
in interfaceDigitalPicture
- Returns:
- the file name associated with the picture
-
setFileName
Method to set the file name- Parameters:
name
- the full pathname of the file
-
getTitle
Method to get the title of the picture- Specified by:
getTitle
in interfaceDigitalPicture
- Returns:
- the title of the picture
-
setTitle
Method to set the title for the picture- Specified by:
setTitle
in interfaceDigitalPicture
- Parameters:
title
- the title to use for the picture
-
getWidth
public int getWidth()Method to get the width of the picture in pixels- Specified by:
getWidth
in interfaceDigitalPicture
- Returns:
- the width of the picture in pixels
-
getHeight
public int getHeight()Method to get the height of the picture in pixels- Specified by:
getHeight
in interfaceDigitalPicture
- Returns:
- the height of the picture in pixels
-
getPictureFrame
Method to get the picture frame for the picture- Returns:
- the picture frame associated with this picture (it may be null)
-
setPictureFrame
Method to set the picture frame for this picture- Parameters:
pictureFrame
- the picture frame to use
-
getImage
Method to get an image from the picture- Specified by:
getImage
in interfaceDigitalPicture
- Returns:
- the buffered image since it is an image
-
getBasicPixel
public int getBasicPixel(int x, int y) Method to return the pixel value as an int for the given x and y location- Specified by:
getBasicPixel
in interfaceDigitalPicture
- Parameters:
x
- the x coordinate of the pixely
- the y coordinate of the pixel- Returns:
- the pixel value as an integer (alpha, red, green, blue)
-
setBasicPixel
public void setBasicPixel(int x, int y, int rgb) Method to set the value of a pixel in the picture from an int- Specified by:
setBasicPixel
in interfaceDigitalPicture
- Parameters:
x
- the x coordinate of the pixely
- the y coordinate of the pixelrgb
- the new rgb value of the pixel (alpha, red, green, blue)
-
getPixel
Method to get a pixel object for the given x and y location- Specified by:
getPixel
in interfaceDigitalPicture
- Parameters:
x
- the x location of the pixel in the picturey
- the y location of the pixel in the picture- Returns:
- a Pixel object for this location
-
getPixels
Method to get a one-dimensional array of Pixels for this simple picture- Returns:
- a one-dimensional array of Pixel objects starting with y=0 to y=height-1 and x=0 to x=width-1.
-
load
Method to load the buffered image with the passed image- Parameters:
image
- the image to use
-
show
public void show()Method to show the picture in a picture frame- Specified by:
show
in interfaceDigitalPicture
-
hide
public void hide()Method to hide the picture -
setVisible
public void setVisible(boolean flag) Method to make this picture visible or not- Parameters:
flag
- true if you want it visible else false
-
repaint
public void repaint()Method to open a picture explorer on a copy of this simple picture -
addMessage
Method to write the contents of the picture to a file with the passed name without throwing errors- Parameters:
fileName
- the name of the file to write the picture to
-
drawString
Method to draw a string at the given location on the picture- Parameters:
text
- the text to drawxPos
- the left x for the textyPos
- the top y for the text
-
scale
Method to create a new picture by scaling the current picture by the given x and y factors- Parameters:
xFactor
- the amount to scale in xyFactor
- the amount to scale in y- Returns:
- the resulting picture
-
getPictureWithWidth
Method to create a new picture of the passed width. The aspect ratio of the width and height will stay the same.- Parameters:
width
- the desired width- Returns:
- the resulting picture
-
getPictureWithHeight
Method to create a new picture of the passed height. The aspect ratio of the width and height will stay the same.- Parameters:
height
- the desired height- Returns:
- the resulting picture
-
getTransformEnclosingRect
Method to get the coordinates of the enclosing rectangle after this transformation is applied to the current picture- Returns:
- the enclosing rectangle
-
getTranslationEnclosingRect
Method to get the coordinates of the enclosing rectangle after this transformation is applied to the current picture- Returns:
- the enclosing rectangle
-
toString
-