org.lyra.Widgets
Class GraphicsUtilities

java.lang.Object
  extended by org.lyra.Widgets.GraphicsUtilities

public class GraphicsUtilities
extends java.lang.Object

Contains various static functions that can be employed to perform certain operations on images.

Since:
1.0.1
Version:
1.0.5, %Revision, 174%, %LastChangedDate, 27/10/12 3:33PM%
Author:
Martin Foster

Constructor Summary
GraphicsUtilities()
           
 
Method Summary
static java.awt.image.BufferedImage getScaledInstance(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint, boolean higherQuality)
          Convenience method that returns a scaled instance of the provided BufferedImage.
static java.awt.Image getScaledInstance(java.awt.Image img, int targetWidth, int targetHeight, java.lang.Object hint, boolean higherQuality)
          Convenience method that returns a scaled instance of the provided BufferedImage.
static boolean hasAlpha(java.awt.Image image)
          When provided with an instance of Image will determine if there are transparency pixels in place.
static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image)
          This method will take an instance of Image and convert it to an instance of BufferedImage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphicsUtilities

public GraphicsUtilities()
Method Detail

getScaledInstance

public static java.awt.image.BufferedImage getScaledInstance(java.awt.image.BufferedImage img,
                                                             int targetWidth,
                                                             int targetHeight,
                                                             java.lang.Object hint,
                                                             boolean higherQuality)
                                                      throws java.lang.NullPointerException
Convenience method that returns a scaled instance of the provided BufferedImage.

Parameters:
img - the original image to be scaled
targetWidth - the desired width of the scaled instance, in pixels
targetHeight - the desired height of the scaled instance, in pixels
hint - one of the rendering hints that corresponds to RenderingHints.KEY_INTERPOLATION (e.g. RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RenderingHints.VALUE_INTERPOLATION_BICUBIC)
higherQuality - if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in down scaling cases, where targetWidth or targetHeight is smaller than the original dimensions, and generally only when the BILINEAR hint is specified)
Returns:
a scaled version of the original BufferedImage
Throws:
java.lang.NullPointerException

getScaledInstance

public static java.awt.Image getScaledInstance(java.awt.Image img,
                                               int targetWidth,
                                               int targetHeight,
                                               java.lang.Object hint,
                                               boolean higherQuality)
                                        throws java.lang.NullPointerException
Convenience method that returns a scaled instance of the provided BufferedImage.

Parameters:
img - the original image to be scaled
targetWidth - the desired width of the scaled instance, in pixels
targetHeight - the desired height of the scaled instance, in pixels
hint - one of the rendering hints that corresponds to RenderingHints.KEY_INTERPOLATION (e.g. RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RenderingHints.VALUE_INTERPOLATION_BICUBIC)
higherQuality - if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in down scaling cases, where targetWidth or targetHeight is smaller than the original dimensions, and generally only when the BILINEAR hint is specified)
Returns:
a scaled version of the original BufferedImage
Throws:
java.lang.NullPointerException

toBufferedImage

public static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image)
                                                    throws java.lang.NullPointerException
This method will take an instance of Image and convert it to an instance of BufferedImage. That in turn can be used in our scaled Instance handler.

Parameters:
image - Instance of image.
Returns:
Instance of BufferedImage.
Throws:
java.lang.NullPointerException

hasAlpha

public static boolean hasAlpha(java.awt.Image image)
                        throws java.lang.NullPointerException
When provided with an instance of Image will determine if there are transparency pixels in place. If this is the case, we will return true to indicate as such.

Parameters:
image - Instance of the image.
Returns:
Boolean indicating alpha/non-alpha information.
Throws:
java.lang.NullPointerException