|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object EzImage
public class EzImage
The EzImage class makes accessing and manipulating images straightforward.
Images can be loaded from files in GIF, JPEG, or PNG format and manipulated
through a variety of array operations.
Both gray-scale and color images are supported.
The ideas and much of the code are largely from the class EasyBufferedImage
by Kenny Hunt at UW-Lacrosse.
Field Summary | |
---|---|
static Integer |
ALPHA
|
static Integer |
BLUE
|
static Integer |
GRAY
|
static Integer |
GREEN
|
static Integer |
RED
|
Constructor Summary | |
---|---|
EzImage(java.awt.image.BufferedImage image)
Constructs an EzImage object by wrapping around a BufferedImage object. |
|
EzImage(java.io.File file)
Constructs an EzImage object from the File object indicated. |
|
EzImage(Integer[][] pixels)
Constructs an EzImage object represented by the specified pixels. |
|
EzImage(Integer[][][] pixels)
Constructs an EzImage object represented by the specified pixels. |
|
EzImage(Integer[] pixels,
Integer height,
Integer width)
Constructs an EzImage object represented by the specified pixels. |
|
EzImage(String filename)
Constructs an EzImage object by reading the image file specified by the filename. |
|
EzImage(java.net.URL url)
Constructs an EzImage object by reading the image specified by the url. |
Method Summary | |
---|---|
EzImage |
copy()
Returns a copy of the calling EzImage. |
EzImage |
copyToGrayScale()
Returns an EzImage object that is a gray-scale copy. |
java.awt.image.BufferedImage |
getBufferedImage()
Returns the image in BufferedImage format. |
Integer |
getHeight()
Returns the height of the image. |
Integer[] |
getPixels1D()
Returns a 1D array of pixel values corresponding to gray values. |
Integer[] |
getPixels1D(Integer band)
Returns a 1D array of pixel values corresponding to the specified band. |
Integer[][] |
getPixels2D()
Returns a 2D array of pixel values corresponding to gray values. |
Integer[][] |
getPixels2D(Integer band)
Returns a 2D array of pixel values corresponding to the specified band. |
Integer[][][] |
getPixels3D()
Returns a 3D array of pixel values. |
String[] |
getSupportedWritingFormats()
Returns a String array listing the file formats supported by this class for writing. |
Integer |
getWidth()
Returns the width of the image. |
Boolean |
isColor()
Returns true if the image is a color image and false otherwise. |
static void |
main(String[] args)
The main method for this class. |
Integer |
numColorBands()
Returns the number of color bands present in the image. |
void |
save(String filename,
String format)
Creates an image file having the specified name and of the specified format. |
void |
setPixels(Integer[] pixels)
Sets all of the EzImage pixels. |
void |
setPixels(Integer[][] pixels)
Sets all of the EzImage pixels. |
void |
setPixels(Integer[][][] pixels)
Sets all of the EzImage pixels. |
void |
setPixels(Integer[][] pixels,
Integer band)
Sets all of the EzImage pixels in the specified band. |
void |
setPixels(Integer[] pixels,
Integer band)
Sets all of the EzImage pixels in the specified band. |
void |
show()
Creates a window that will display this EzImage. |
void |
show(String title)
Creates a window that will display this EzImage. |
void |
show(String title,
Integer row,
Integer column)
Creates a window that will display this EzImage. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Integer RED
public static final Integer GREEN
public static final Integer BLUE
public static final Integer GRAY
public static final Integer ALPHA
Constructor Detail |
---|
public EzImage(Integer[][] pixels)
pixels
- an array of [height][width] pixels that represents the
image
IllegalArgumentException
- if pixels is nullpublic EzImage(Integer[][][] pixels)
pixels
- an array of [height][width][bands] pixels that
represents the image.
IllegalArgumentException
- if pixels is nullpublic EzImage(Integer[] pixels, Integer height, Integer width)
pixels
- an array of [height * width] pixels that represents the
image.width
- the width (in pixels) of the image.height
- the height (in pixels) of the image.
IllegalArgumentException
- if pixels is null or the
length is not width * height.public EzImage(java.awt.image.BufferedImage image)
image
- a BufferedImage objectpublic EzImage(String filename) throws java.io.FileNotFoundException, java.io.IOException
filename
- the name of the file to load
java.io.FileNotFoundException
java.io.IOException
public EzImage(java.io.File file) throws java.io.IOException, java.io.FileNotFoundException
file
- the File object to load
IOException,FileNotFoundException
java.io.IOException
java.io.FileNotFoundException
public EzImage(java.net.URL url) throws java.io.IOException
url
- the URL of an image file to load.
java.io.IOException
Method Detail |
---|
public EzImage copyToGrayScale()
public Integer[][][] getPixels3D()
public Integer[][] getPixels2D(Integer band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAY
IllegalArgumentException
- if gray band is requested from
color image, or vice-versapublic Integer[][] getPixels2D()
UnsupportedOperationException
- if image is colorpublic Integer[] getPixels1D(Integer band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAY
IllegalArgumentException
- if gray band is requested from
color image, or vice-versapublic Integer[] getPixels1D()
UnsupportedOperationException
- if image is colorpublic void setPixels(Integer[] pixels)
pixels
- an array of pixels.
UnsupportedOperationException
- if image is colorpublic void setPixels(Integer[] pixels, Integer band)
pixels
- an array of the "new" image for the specified band.band
- one of GRAY, RED, GREEN, BLUE, or ALPHA
IllegalArgumentException
- if the pixels array is not
compatible with the image, or if an illegal color band
is specified.public void setPixels(Integer[][] pixels)
pixels
- an array of pixels.
UnsupportedOperationException
- if image is colorpublic void setPixels(Integer[][] pixels, Integer band)
pixels
- an array of the "new" image for the specified band.band
- one of GRAY, RED, GREEN, BLUE, or ALPHA
IllegalArgumentException
- if the pixels array is not
compatible with the image, or if an illegal color band
is specified.public void setPixels(Integer[][][] pixels)
pixels
- a 3D array of HEIGHT by WIDTH by DEPTH pixels of the
image
IllegalArgumentException
- if the pixels array is not
compatible with the image.public Boolean isColor()
IllegalStateException
- if the number of bands is nonsensical.public Integer numColorBands()
public String[] getSupportedWritingFormats()
public java.awt.image.BufferedImage getBufferedImage()
public Integer getHeight()
public Integer getWidth()
public EzImage copy()
public void show(String title)
title
- the title of the windowpublic void show()
public void show(String title, Integer row, Integer column)
title
- the title of the windowrow
- the row coordinate of the upper left corner of the
windowcolumn
- the column coordinate of the upper left corner of the
windowpublic void save(String filename, String format) throws java.io.IOException
filename
- the name of the file to be savedformat
- String containing one of the supported Java file
types
java.io.IOException
- if the file cannot be created,
IllegalArgumentException if the file type is not
supportedpublic static void main(String[] args) throws java.io.IOException
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |