org.minueto.image
Class MinuetoImage

java.lang.Object
  extended by org.minueto.image.MinuetoImage
All Implemented Interfaces:
java.lang.Cloneable, MinuetoDrawingSurface
Direct Known Subclasses:
MinuetoCircle, MinuetoImageFile, MinuetoRectangle, MinuetoText

public class MinuetoImage
extends java.lang.Object
implements java.lang.Cloneable, MinuetoDrawingSurface

The MinuetoImage class describes an image that can be drawn on a MinuetoWindow. All other types of images used by Minueto are subclasses of MinuetoImage.

Basic 2D image transformations (such as crop, scale, rotate) can be executed on any MinuetoImage. These transformation produce new MinuetoImage that can be manipulated independently from their original image.Please note that these transformations are slow and should not be used in realtime. Results from these operations should be preferably cached in advanced.

Images are created at the same colordepth as MinuetoWindow. When created, a MinuetoImage is transparent. Other MinuetoImage can be draw over it, thus allowing you to build more complexe composite images.

Since:
Minueto 0.4

Constructor Summary
MinuetoImage(java.awt.image.BufferedImage image)
          Create an image using an existing buffered image.
MinuetoImage(int x, int y)
          Create a blank (transparent) image of the specified width and height.
 
Method Summary
 void clear()
          Clears the contents of the Drawing Surface.
 void clear(MinuetoColor color)
          Erases the contents from the Drawing Surface.
 java.lang.Object clone()
          Creates and returns a copy of this MinuetoImage.
 MinuetoImage crop(int cornerX, int cornerY, int sizeX, int sizeY)
          Return a cropped copy of this MinuetoImage.
 void draw(MinuetoImage image, int x, int y)
          Draw another MinuetoImage on this MinuetoDrawingSurface (thus compositing them).
 void drawCircle(MinuetoColor color, int x, int y, int diameter)
          Draw a circle of the specified color at the start point and of the desired diameter.
 void drawLine(MinuetoColor color, int xStart, int yStart, int xStop, int yStop)
          Draw a line of the specified color from the start point to the end point.
 void drawPolygon(MinuetoColor color, int[] points)
          Draw a polygon of the specified color from the specified points.
 void drawRectangle(MinuetoColor color, int x, int y, int width, int height)
          Draw a rectangle of the specified color from the start point and of the desired size.
 MinuetoImage flip(boolean horizontal, boolean vertical)
          Returns a flipped copy of this MinuetoImage.
 int getHeight()
          Return the height of the image.
 MinuetoColor getPixel(int x, int y)
          Get the color of the pxel at location x,y.
 int getWidth()
          Return the width of the image.
 MinuetoImage mask(MinuetoColor color)
          The mask method creates a new MinuetoImage where all the non-transparent pxels of this image are replaced with the provided color.
 MinuetoImage rotate(double dAngle)
          Return a rotated copy of this MinuetoImage.
 void save(java.lang.String filename)
          Saves the content of the MinuetoDrawingSurface to a PNG file.
 MinuetoImage scale(double factorX, double factorY)
          Return a scaled copy of this MinuetoImage.
 void setPixel(int x, int y, MinuetoColor color)
          Change the color of pxel at location X,y.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MinuetoImage

public MinuetoImage(int x,
                    int y)
Create a blank (transparent) image of the specified width and height.

Parameters:
x - int int denoting the width of the blank image.
y - intThrows:
MinuetoZeroNegativeException - if the image size is invalid.

MinuetoImage

public MinuetoImage(java.awt.image.BufferedImage image)
Create an image using an existing buffered image.

Parameters:
image - BufferedImage witht he content of the image.
Method Detail

crop

public MinuetoImage crop(int cornerX,
                         int cornerY,
                         int sizeX,
                         int sizeY)
Return a cropped copy of this MinuetoImage. The action of cropping an image can be described as copying a portion of an image to a new image.

Parameters:
cornerX - int denoting the X coordinate of the upper left corner of the old image to be used as the upper left corner of the new image..
cornerY - int denoting the Y coordinate of the upper left corner. of the old image to be used as the upper left corner of the new image.
sizeX - int denoting the width of the portion of the old image to copy in the new image.
sizeY - int denoting the height of the portion of the old image to copy in the new image.
Returns:
MinuetoImage of the cropped image.
Throws:
MinuetoZeroNegativeException - if an invalid position or size is used.
MinuetoOutOfBoundException - if a

rotate

public MinuetoImage rotate(double dAngle)
Return a rotated copy of this MinuetoImage. The angle must be supplied in radian.

Parameters:
dAngle - double denoting the rotation angle in radian.
Returns:
MinuetoImage of the rotated image.

scale

public MinuetoImage scale(double factorX,
                          double factorY)
Return a scaled copy of this MinuetoImage. The parameters are described as scale factors. Thus, calling the scale function with the 2,2 parameters would create a image of double width and height.

Parameters:
factorX - double denoting how the image should be scaled on the X axis.
factorY - double denoting how the image should be scaled on the Y axis.
Returns:
MinuetoImage of the scaled image.
Throws:
MinuetoZeroNegativeException - if a wrong scale factor is used.

mask

public MinuetoImage mask(MinuetoColor color)
The mask method creates a new MinuetoImage where all the non-transparent pxels of this image are replaced with the provided color.

Parameters:
color - MinuetoColor denoting the color of the mask.
Returns:
MinuetoImage of the mask

flip

public MinuetoImage flip(boolean horizontal,
                         boolean vertical)
Returns a flipped copy of this MinuetoImage. The image can be flipped vertically, horizontally, or both. For example, flip(true, false) would flip the image horizontally.

Parameters:
horizontal - boolean if the image should be flipped on the X axis.
vertical - boolean if the image should be flipped on the Y axis.
Returns:
MinuetoImage of the flipped image.
Since:
0.45

setPixel

public void setPixel(int x,
                     int y,
                     MinuetoColor color)
Description copied from interface: MinuetoDrawingSurface
Change the color of pxel at location X,y.

This uses the drawLine function to be faster than a direct raw data setPxel, though it should be used with caution as it is still slower than drawing a completed image to the drawing surface.

Specified by:
setPixel in interface MinuetoDrawingSurface
Parameters:
x - int denoting which pxel on the X axis should be colored.
y - int denoting which pxel on the y axis should be colored.
color - MinuetoColor denoting the new color for pxel x,y.

getPixel

public MinuetoColor getPixel(int x,
                             int y)
Get the color of the pxel at location x,y.

Note: Pxel manipulation of a MinuetoImage is a very slow operation. It should not be used in realtime.

Parameters:
x - int denoting which pxel on the X axis we are targeting.
y - int denoting which pxel on the y axis we are targeting.
Returns:
MinuetoColor denoting the color of the specified pxel.
Since:
1.1

clear

public void clear()
Description copied from interface: MinuetoDrawingSurface
Clears the contents of the Drawing Surface. The color that remains depends on the JVM.

Specified by:
clear in interface MinuetoDrawingSurface

clear

public void clear(MinuetoColor color)
Description copied from interface: MinuetoDrawingSurface
Erases the contents from the Drawing Surface. The color of the cleared surface is specified as a parameter.

Specified by:
clear in interface MinuetoDrawingSurface
Parameters:
color - MinuetoColor of the cleared buffer.

draw

public void draw(MinuetoImage image,
                 int x,
                 int y)
Description copied from interface: MinuetoDrawingSurface
Draw another MinuetoImage on this MinuetoDrawingSurface (thus compositing them).

Specified by:
draw in interface MinuetoDrawingSurface
Parameters:
image - MinuetoImage that we will draw on our image.
x - int denoting where we should start drawing on the x axis.
y - int denothing where we should start drawing on the y axis.

drawLine

public void drawLine(MinuetoColor color,
                     int xStart,
                     int yStart,
                     int xStop,
                     int yStop)
Description copied from interface: MinuetoDrawingSurface
Draw a line of the specified color from the start point to the end point.

Specified by:
drawLine in interface MinuetoDrawingSurface
Parameters:
color - MinuetoColor denoting the color of the line.
xStart - int denoting the X value of the start point.
yStart - int denoting the Y value of the start point.
xStop - int denoting the X value of the end point.
yStop - int denoting the Y value of the end point.

getWidth

public int getWidth()
Description copied from interface: MinuetoDrawingSurface
Return the width of the image.

Specified by:
getWidth in interface MinuetoDrawingSurface
Returns:
int denoting the width of the image.

getHeight

public int getHeight()
Description copied from interface: MinuetoDrawingSurface
Return the height of the image.

Specified by:
getHeight in interface MinuetoDrawingSurface
Returns:
int denoting the height of the image.

drawRectangle

public void drawRectangle(MinuetoColor color,
                          int x,
                          int y,
                          int width,
                          int height)
Draw a rectangle of the specified color from the start point and of the desired size.

Parameters:
color - MinuetoColor denoting the color of the rectangle.
x - int denoting the x value of the start point.
y - int denoting the y value of the start point.
width - int denoting the width of the rectangle.
height - int denoting the height of the rectangle.
Throws:
MinuetoOutOfBoundException - if the target coordinates are not valid.

drawPolygon

public void drawPolygon(MinuetoColor color,
                        int[] points)
Draw a polygon of the specified color from the specified points. Points are specified in a single integer array in the following format : {x1,y1,x2,y2,...}

Parameters:
color - MinuetoColor denoting the color of the rectangle.
points - int[] denoting the points of the polygon.

drawCircle

public void drawCircle(MinuetoColor color,
                       int x,
                       int y,
                       int diameter)
Draw a circle of the specified color at the start point and of the desired diameter.

Parameters:
color - MinuetoColor denoting the color of the circle.
x - int denoting the x value of the start point.
y - int denoting the y value of the start point.
diameter - int denoting the diameter of the circle.
Throws:
MinuetoOutOfBoundException - if the target coordinates are not valid.

save

public void save(java.lang.String filename)
          throws MinuetoFileException
Description copied from interface: MinuetoDrawingSurface
Saves the content of the MinuetoDrawingSurface to a PNG file. Since this method requires File I/O, it is somewhat slow. However, this method can be used as a debugging tool.

Specified by:
save in interface MinuetoDrawingSurface
Parameters:
filename - String indicating the name of the PNG file.
Throws:
MinuetoFileException

clone

public java.lang.Object clone()
Creates and returns a copy of this MinuetoImage. The returned MinuetoImage is independant from this MinuetoImage.

Overrides:
clone in class java.lang.Object