|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Image
java.awt.image.BufferedImage
EasyBufferedImage
public class EasyBufferedImage
Represents an image that can be manipulated without a thorough understanding of the built-in image classes. Performance (in terms of memory and speed) is sacrificed in order to provide simplified access to pixel data. Allows direct read/write access to individual pixels and a factory method for creating EasyBufferedImages from files. The image always appears as either a gray-scale image, an RGB image or an RGBA image. The data is never packed or interleaved (at least with respect to the get/set pixel methods).
Please note that grayscale processing of a color image always maintains the color information of the image while altering the intensity channel. To perform operations on a purely gray-scale image, convert any color images to grayscale prior to processing.
Since the EasyBufferedImage class is a sub-class of Image and BufferedImage, it is fully integrated into the standard Swing libraries for viewing and manipulation. To create an EasyBufferedImage you must use the factory method shown below:
where the filename is a String representing an image file in either GIF, PNG, or JPEG
formats. The following code fragment is an example of how to invert a gray-scale image:
EasyBufferedImage image = EasyBufferedImage.createImage(filename);
int[] pixels = image.getPixels1D(EasyBufferedImage.GRAY);
for(int i=0; i < pixels.length; i++) {
pixels[i] = 255-pixels[i];
}
image.setPixels(pixels);
Image
,
BufferedImage
,
Serialized FormField Summary | |
---|---|
static int |
ALPHA
|
static int |
BLUE
|
static int |
GIF
|
static int |
GRAY
|
static int |
GREEN
|
static int |
JPEG
|
static int |
PNG
|
static int |
RED
|
Fields inherited from class java.awt.image.BufferedImage |
---|
TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE, TYPE_BYTE_BINARY, TYPE_BYTE_GRAY, TYPE_BYTE_INDEXED, TYPE_CUSTOM, TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_INT_BGR, TYPE_INT_RGB, TYPE_USHORT_555_RGB, TYPE_USHORT_565_RGB, TYPE_USHORT_GRAY |
Fields inherited from class java.awt.Image |
---|
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty |
Fields inherited from interface java.awt.Transparency |
---|
BITMASK, OPAQUE, TRANSLUCENT |
Method Summary | |
---|---|
static int |
clamp(double v)
Returns the value of v clamped to the range 0-255. |
EasyBufferedImage |
copy()
Returns a copy of the calling EasyBufferedImage. |
EasyBufferedImage |
copyToGrayScale()
Returns an EasyBufferedImage object that is a gray-scale copy of the calling image. |
static EasyBufferedImage |
createImage(java.awt.image.BufferedImage image)
|
static EasyBufferedImage |
createImage(java.io.File file)
|
static EasyBufferedImage |
createImage(int[][] pixels)
Returns an EasyBufferedImage object represented by the specified pixels. |
static EasyBufferedImage |
createImage(int[][][] pixels)
Returns an EasyBufferedImage object represented by the specified pixels. |
static EasyBufferedImage |
createImage(int[] pixels,
int width,
int height)
Returns an EasyBufferedImage object represented by the specified pixels. |
static EasyBufferedImage |
createImage(java.lang.String filename)
Returns an EasyBufferedImage object by reading the image file specified by the filename. |
static EasyBufferedImage |
createImage(java.net.URL url)
Returns an EasyBufferedImage object by reading the image specified by the url. |
int[] |
getPixels1D()
Returns a 1D array of pixel values corresponding to the specified band. |
int[] |
getPixels1D(int band)
Returns a 1D array of pixel values corresponding to the specified band. |
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[] |
getSupportedFormats()
Returns a String array listing the file formats supported by this class. |
boolean |
isColor()
Returns true if the image is a color image and false otherwise. |
static void |
main(java.lang.String[] args)
A demo application that shows simple ways of using the EasyBufferedImage class. |
void |
save(java.lang.String filename,
int format)
Creates an image file having the specified name and of the specified format. |
void |
setPixels(int[][][] pixels)
Sets all of the EasyBufferedImages pixels. |
void |
setPixels(int[][] pixels,
int band)
Sets all of the EasyBufferedImages pixels in the specified band. |
void |
setPixels(int[] pixels,
int band)
Sets all of the EasyBufferedImages pixels in the specified band. |
void |
show(java.lang.String title)
Creates a window that will display this EasyBufferedImage This method maintains a count of all windows opened via calls to this method and will terminate the application if all such windows are closed. |
Methods inherited from class java.awt.image.BufferedImage |
---|
addTileObserver, coerceData, copyData, createGraphics, flush, getAlphaRaster, getCapabilities, getColorModel, getData, getData, getGraphics, getHeight, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getProperty, getProperty, getPropertyNames, getRaster, getRGB, getRGB, getSampleModel, getSource, getSources, getSubimage, getTile, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getTransparency, getType, getWidth, getWidth, getWritableTile, getWritableTileIndices, hasTileWriters, isAlphaPremultiplied, isTileWritable, releaseWritableTile, removeTileObserver, setData, setRGB, setRGB, toString |
Methods inherited from class java.awt.Image |
---|
getAccelerationPriority, getScaledInstance, setAccelerationPriority |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int GRAY
public static final int RED
public static final int GREEN
public static final int BLUE
public static final int ALPHA
public static final int JPEG
public static final int GIF
public static final int PNG
Method Detail |
---|
public java.lang.String[] getSupportedFormats()
none
-
public static EasyBufferedImage createImage(java.awt.image.BufferedImage image)
public static EasyBufferedImage createImage(java.lang.String filename) throws java.io.FileNotFoundException
filename
- the name of the file to load.
java.io.FileNotFoundException
Image
,
BufferedImage
public static EasyBufferedImage createImage(java.io.File file) throws java.io.IOException, java.io.FileNotFoundException
java.io.IOException
java.io.FileNotFoundException
public static EasyBufferedImage createImage(java.net.URL url)
url
- is the URL of an image file to load.
Image
,
BufferedImage
public static EasyBufferedImage createImage(int[][][] pixels)
pixels
- is an array of [height][width][bands] pixels that represents the image.
java.lang.IllegalArgumentException
- if pixels is nullImage
,
BufferedImage
public static EasyBufferedImage createImage(int[][] pixels)
pixels
- is an array of [height][width] pixels that represents the image.
java.lang.IllegalArgumentException
- if pixels is nullImage
,
BufferedImage
public static EasyBufferedImage createImage(int[] pixels, int width, int height)
pixels
- is an array of [height * width] pixels that represents the image.height
- is the height (in pixels) of the image.width
- is the width (in pixels) of the image.
java.lang.IllegalArgumentException
- if pixels is null or the length is not width * height.Image
,
BufferedImage
public static int clamp(double v)
v
- is the value of a pixel to be clamped.
public EasyBufferedImage copyToGrayScale()
None
-
public int[][][] getPixels3D()
None
-
public int[][] getPixels2D(int band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAY
public int[] getPixels1D(int band)
band
- is either RED, GREEN, BLUE, ALPHA, or GRAY
public int[] getPixels1D()
public void setPixels(int[] pixels, int band)
pixels
- is an array of the "new" image for the specified band.band
- is one of GRAY, RED, GREEN, BLUE, or ALPHA
java.lang.IllegalArgumentException
- if the pixels array is not compatible with the image.public void setPixels(int[][] pixels, int band)
pixels
- is an array of the "new" image in the specified band.band
- is one of GRAY, RED, GREEN, BLUE, or ALPHA
java.lang.IllegalArgumentException
- if the pixels array is not compatible with the image.public void setPixels(int[][][] pixels)
pixels
- is 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()
None
-
public EasyBufferedImage copy()
None
-
public void show(java.lang.String title)
None
- public void save(java.lang.String filename, int format) throws java.io.IOException
filename
- the name of the file to be savedformat
- one of EasyBufferedImage.PNG, EasyBufferedImage.GIF or EasyBufferedImage.JPEG
java.io.IOException
- if the file cannot be created.public static void main(java.lang.String[] args) throws java.io.IOException
where the AlphaValue is a percentage value in the range [0..100] and serves as a brightness control. Values in the range
[0..1) will darken the image while values above 1 will brighten the input image. This application also saves the processed
file in GIF format to a file named "Sample.gif".
java EasyBufferedImage ImageFileName AlphaValue
public static void main(String[] args) throws IOException
{
EasyBufferedImage image = EasyBufferedImage.createImage(args[0]);
double alpha = Double.parseDouble(args[1]);
EasyBufferedImage copy = image.copy();
int[][] data = image.getPixels2D(EasyBufferedImage.RED);
for(int i=0; i < image.getHeight(); i++)
{
for(int j=0; j < image.getWidth(); j++)
{
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.RED);
data = image.getPixels2D(EasyBufferedImage.GREEN);
for(int i=0; i < image.getHeight(); i++)
{
for(int j=0; j < image.getWidth(); j++)
{
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.GREEN);
data = image.getPixels2D(EasyBufferedImage.BLUE);
for(int i=0; i < image.getHeight(); i++){
for(int j=0; j < image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.BLUE);
image.show(args[0]);
data = copy.getPixels2D(EasyBufferedImage.GRAY);
for(int i=0; i < copy.getHeight(); i++){
for(int j=0; j < copy.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
copy.setPixels(data, EasyBufferedImage.GRAY);
copy.show("GRAY SCALE PROCESSING");
image.save("Sample.gif", EasyBufferedImage.GIF);
}
args
- is an array of two strings. The first is the filename of the file to process and the second is a perctage value to brighten/darken an image.
IOException.
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |