|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.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 int |
ALPHA
|
static int |
BLUE
|
static int |
GRAY
|
static int |
GREEN
|
static int |
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(int[][] pixels)
Constructs an EzImage object represented by the specified pixels. |
|
EzImage(int[][][] pixels)
Constructs an EzImage object represented by the specified pixels. |
|
EzImage(int[] pixels,
int height,
int width)
Constructs an EzImage object represented by the specified pixels. |
|
EzImage(java.lang.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. |
int |
getHeight()
Returns the height of the image. |
int[] |
getPixels1D()
Returns a 1D array of pixel values corresponding to gray values. |
int[] |
getPixels1D(int band)
Returns a 1D array of pixel values corresponding to the specified band. |
int[][] |
getPixels2D()
Returns a 2D array of pixel values corresponding to gray values. |
int[][] |
getPixels2D(int band)
Returns a 2D array of pixel values corresponding to the specified band. |
int[][][] |
getPixels3D()
Returns a 3D array of pixel values. |
java.lang.String[] |
getSupportedWritingFormats()
Returns a String array listing the file formats supported by this class for writing. |
int |
getWidth()
Returns the width of the image. |
boolean |
isColor()
Returns true if the image is a color image and false otherwise. |
static void |
main(java.lang.String[] args)
The main method for this class. |
int |
numColorBands()
Returns the number of color bands present in the image. |
void |
save(java.lang.String filename,
java.lang.String format)
Creates an image file having the specified name and of the specified format. |
void |
setPixels(int[] pixels)
Sets all of the EzImage pixels. |
void |
setPixels(int[][] pixels)
Sets all of the EzImage pixels. |
void |
setPixels(int[][][] pixels)
Sets all of the EzImage pixels. |
void |
setPixels(int[][] pixels,
int band)
Sets all of the EzImage pixels in the specified band. |
void |
setPixels(int[] pixels,
int band)
Sets all of the EzImage pixels in the specified band. |
void |
show(java.lang.String title)
Creates a window that will display this EzImage. |
void |
show(java.lang.String title,
int row,
int column)
Creates a window that will display this EzImage. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int RED
public static final int GREEN
public static final int BLUE
public static final int GRAY
public static final int ALPHA
Constructor Detail |
---|
public EzImage(int[][] pixels)
pixels
- an array of [height][width] pixels that represents the
image
java.lang.IllegalArgumentException
- if pixels is nullpublic EzImage(int[][][] pixels)
pixels
- an array of [height][width][bands] pixels that
represents the image.
java.lang.IllegalArgumentException
- if pixels is nullpublic EzImage(int[] pixels, int height, int 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.
java.lang.IllegalArgumentException
- if pixels is null or the
length is not width * height.public EzImage(java.awt.image.BufferedImage image)
image
- a BufferedImage objectpublic EzImage(java.lang.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 int[][][] getPixels3D()
public int[][] getPixels2D(int band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAY
java.lang.IllegalArgumentException
- if gray band is requested from
color image, or vice-versapublic int[][] getPixels2D()
java.lang.UnsupportedOperationException
- if image is colorpublic int[] getPixels1D(int band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAY
java.lang.IllegalArgumentException
- if gray band is requested from
color image, or vice-versapublic int[] getPixels1D()
java.lang.UnsupportedOperationException
- if image is colorpublic void setPixels(int[] pixels)
pixels
- an array of pixels.
java.lang.UnsupportedOperationException
- if image is colorpublic void setPixels(int[] pixels, int band)
pixels
- an array of the "new" image for the specified band.band
- one of GRAY, RED, GREEN, BLUE, or ALPHA
java.lang.IllegalArgumentException
- if the pixels array is not
compatible with the image, or if an illegal color band
is specified.public void setPixels(int[][] pixels)
pixels
- an array of pixels.
java.lang.UnsupportedOperationException
- if image is colorpublic void setPixels(int[][] pixels, int band)
pixels
- an array of the "new" image for the specified band.band
- one of GRAY, RED, GREEN, BLUE, or ALPHA
java.lang.IllegalArgumentException
- if the pixels array is not
compatible with the image, or if an illegal color band
is specified.public void setPixels(int[][][] pixels)
pixels
- a 3D array of HEIGHT by WIDTH by DEPTH pixels of the
image
java.lang.IllegalArgumentException
- if the pixels array is not
compatible with the image.public boolean isColor()
java.lang.IllegalStateException
- if the number of bands is nonsensical.public int numColorBands()
public java.lang.String[] getSupportedWritingFormats()
public java.awt.image.BufferedImage getBufferedImage()
public int getHeight()
public int getWidth()
public EzImage copy()
public void show(java.lang.String title)
title
- the title of the windowpublic void show(java.lang.String title, int row, int 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(java.lang.String filename, java.lang.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(java.lang.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 |