public class EzImage
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ALPHA |
static int |
BLUE |
static int |
GRAY |
static int |
GREEN |
static int |
RED |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
EzImage |
appendToRight(EzImage image)
Creates a new image that has this image on the left
and the input image on the right (with no space in between.
|
EzImage |
copy()
Returns a copy of the calling EzImage.
|
EzImage |
copyToGrayScale()
Returns an EzImage object that is a gray-scale copy.
|
int |
getBluePixel(int h,
int w)
Returns a single pixel value in the BLUE band.
|
java.awt.image.BufferedImage |
getBufferedImage()
Returns the image in BufferedImage format.
|
int |
getGrayPixel(int h,
int w)
Returns a single pixel value in the GRAY band.
|
int |
getGreenPixel(int h,
int w)
Returns a single pixel value in the GREEN band.
|
int |
getHeight()
Returns the height of the image.
|
int |
getPixel(int h,
int w,
int band)
Returns a single pixel value.
|
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.
|
int |
getRedPixel(int h,
int w)
Returns a single pixel value in the RED band.
|
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 |
setBluePixel(int h,
int w,
int value)
Sets a single blue EzImage pixel value in the specified band to the specified value.
|
void |
setGrayPixel(int h,
int w,
int value)
Sets a single gray EzImage pixel value in the specified band to the specified value.
|
void |
setGreenPixel(int h,
int w,
int value)
Sets a single green EzImage pixel value in the specified band to the specified value.
|
void |
setPixel(int h,
int w,
int band,
int value)
Sets a single EzImage pixel value in the specified band to the specified value.
|
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 |
setRedPixel(int h,
int w,
int value)
Sets a single red EzImage pixel value in the specified band to the specified value.
|
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.
|
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
public EzImage(int[][] pixels)
pixels
- an array of [height][width] pixels that represents the
imagejava.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 loadjava.io.FileNotFoundException
java.io.IOException
public EzImage(java.io.File file) throws java.io.IOException, java.io.FileNotFoundException
file
- the File object to loadIOException,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
public EzImage copyToGrayScale()
public int[][][] getPixels3D()
public int[][] getPixels2D(int band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAYjava.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 GRAYjava.lang.IllegalArgumentException
- if gray band is requested from
color image, or vice-versapublic int[] getPixels1D()
java.lang.UnsupportedOperationException
- if image is colorpublic int getPixel(int h, int w, int band)
h
- the pixel's height valuew
- the pixel's width valueband
- one of GRAY, RED, GREEN, BLUE, or ALPHAjava.lang.IndexOutOfBoundsException
- if the height and width are outside
the image's dimensions.public int getRedPixel(int h, int w)
h
- the pixel's height valuew
- the pixel's width valuepublic int getGreenPixel(int h, int w)
h
- the pixel's height valuew
- the pixel's width valuepublic int getBluePixel(int h, int w)
h
- the pixel's height valuew
- the pixel's width valuepublic int getGrayPixel(int h, int w)
h
- the pixel's height valuew
- the pixel's width valuepublic 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 ALPHAjava.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 ALPHAjava.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
imagejava.lang.IllegalArgumentException
- if the pixels array is not
compatible with the image.public void setPixel(int h, int w, int band, int value)
h
- the height value of the pixel to be modifiedw
- the width value of the pixel to be modifiedband
- one of GRAY, RED, GREEN, BLUE, or ALPHAvalue
- the new pixel valuejava.lang.IndexOutOfBoundsException
- if the user specifies an invalid
color band or a pixel values that's outside the range of
the EzImage dimensions.public void setRedPixel(int h, int w, int value)
h
- the height value of the pixel to be modifiedw
- the width value of the pixel to be modifiedvalue
- the new pixel valuejava.lang.IndexOutOfBoundsException
- if the user specifies a pixel
value that's outside the range of the EzImage dimensions.public void setGreenPixel(int h, int w, int value)
h
- the height value of the pixel to be modifiedw
- the width value of the pixel to be modifiedvalue
- the new pixel valuejava.lang.IndexOutOfBoundsException
- if the user specifies a pixel
value that's outside the range of the EzImage dimensions.public void setBluePixel(int h, int w, int value)
h
- the height value of the pixel to be modifiedw
- the width value of the pixel to be modifiedvalue
- the new pixel valuejava.lang.IndexOutOfBoundsException
- if the user specifies a pixel
value that's outside the range of the EzImage dimensions.public void setGrayPixel(int h, int w, int value)
h
- the height value of the pixel to be modifiedw
- the width value of the pixel to be modifiedvalue
- the new pixel valuejava.lang.IndexOutOfBoundsException
- if the user specifies a pixel
value that's outside the range of the EzImage dimensions.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 appendToRight(EzImage image)
image
- the input image to be on the rightpublic 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
typesjava.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