org.tbee.swing
Class ImageUtils

java.lang.Object
  extended by nl.knowledgeplaza.util.ImageUtils
      extended by org.tbee.swing.ImageUtils

public class ImageUtils
extends nl.knowledgeplaza.util.ImageUtils

This is a small class providing some basic and very often used image functions associated with Swing. For example the gradient image which is often used in conjunction with JPanelWithBackground.

Version:
$Revision: 1.65 $

Field Summary
static int DIAGONAL_LTBR
           
static int DIAGONAL_RTBL
           
static int HORIZONTAL
           
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static int VERTICAL
           
 
Constructor Summary
ImageUtils()
           
 
Method Summary
static BufferedImage addBlur(BufferedImage image)
          Add a blur over the image (using GaussianBlur).
static BufferedImage addGaussianBlur(BufferedImage image, double radius)
          Add a blur over the image (using linear blur).
static BufferedImage addLinearBlur(BufferedImage image, int blurIndex)
          Add a blur over the image (using linear blur).
static BufferedImage addMargin(BufferedImage image, int margin)
          This method is used to easy add a margin for blurring.
static BufferedImage addNoise(BufferedImage image)
          add a bit of noise to the whole image
static BufferedImage addNoise(double noiseFactor, BufferedImage image)
          add a bit of noise to the whole image
static BufferedImage addNoise(double noiseFactor, int x, int y, int width, int height, BufferedImage image)
          add a bit of noise
static BufferedImage addReflectionImage(BufferedImage image)
           
static BufferedImage addReflectionImage(BufferedImage image, float compressionFactor, int reflectionOffset)
          Create a copy of the image with a reflection
static void addText(BufferedImage image, JLabel label)
          Add a contrasted text to an image
static void addText(Graphics2D graphics2D, double x, double y, TextLayout lTitle, Color foreground, Color background)
          Draw a contrasted text
static void applySepiaFilter(BufferedImage img, int sepiaIntensity)
          http://www.rhinocerus.net/forum/lang-java-programmer/574119-sepia-tone-image-filter-java.html
static Color blend(Color color1, Color color2)
          Make an even blend between two colors.
static Color blend(Color color1, Color color2, double ratio)
          Blend two colors.
static BufferedImage brighter(BufferedImage image)
           
static BufferedImage brighter(BufferedImage image, int times)
          make brigher Note: the image itself is altered, use createBufferedImage to work on a copy.
static double brightnessFactor(BufferedImage image)
          calculate a factor for the image's overall brightness
static BufferedImage captureScreen()
          Capture the current screen
static BufferedImage clear(BufferedImage bufferedImage)
           
static double colorDistance(Color color1, Color color2)
          Return the "distance" between two colors.
static double colorDistance(double[] color1, double[] color2)
          Return the "distance" between two colors.
static double colorDistance(double r1, double g1, double b1, double r2, double g2, double b2)
          Return the "distance" between two colors.
static BufferedImage createBufferedImage(Image image)
          Create a buffered image from a regular image
static BufferedImage createBufferedImage(int width, int height)
          Although any BufferedImage can be painted, it is wise to created images that are compatible with the current screen device.
static BufferedImage createBufferedImage(int width, int height, int transparency)
          Although any BufferedImage can be painted, it is wise to created images that are compatible with the current screen device.
static Image createDisabled(BufferedImage image)
          Return a new image that appears disabled
static BufferedImage createEmptyBufferedImage(Image image)
          Create a buffered image from a regular image
static BufferedImage createGradientImage(Color color1, Color color2, Color color3, int direction)
           
static BufferedImage createGradientImage(Color color1, Color color2, Color color3, int direction, int width, int height)
           
static BufferedImage createGradientImage(Color color1, Color color2, int direction)
           
static BufferedImage createGradientImage(Color color1, Color color2, int direction, int width, int heigth)
           
static Image createImage(int[] pixels, int width, int height)
          Create image from pixels
static BufferedImage createImageFromComponent(Component component)
          Create a buffered image from a component
static BufferedImage createImageFromIcon(Icon icon)
          Create a buffered image from a component
static BufferedImage createJLabelImage(JLabel label, int margin, boolean blur)
          Deprecated. use the method which has a double blur parameter
static BufferedImage createJLabelImage(JLabel label, int margin, double blur)
          Convert JLabel to Image
static int[] createPixels(BufferedImage bufferedImage)
          Convert a buffered image into an array of rows of pixels The grabPixels method of the PixelGrabber class extracts the pixel data from an Image object into a one-dimensional array of type int.
static BufferedImage createReflectionImage(BufferedImage image)
           
static BufferedImage createReflectionImage(BufferedImage image, float compressionFactor)
          Create a copy of the image with a reflection
static BufferedImage createShadedImage(BufferedImage image, boolean addShade)
          Create a copy of the image with or without a shadow (beware: this is not a DROP shadow, but an actual image).
static BufferedImage createShadedImage(BufferedImage image, int shadeOffset)
          Create a copy of the image with a shadow (beware: this is not a DROP shadow, but an actual image).
static BufferedImage darker(BufferedImage image)
          make darker Note: the image itself is altered, use createBufferedImage to work on a copy.
static Color darker(Color color, double fraction)
          Make a color darker.
static void drawTextWithGlow(String text, Graphics g, Font font, int glowSize, Color foreground, Color glow, float opacity)
          Draw a glowing text on an image
static BufferedImage flipHorizontal(BufferedImage image)
          swap left and right
static BufferedImage flipVertical(BufferedImage image)
          swap top and bottom
static ConvolveOp getGaussianBlurOp(double stddev)
          Get a ConvolveOp that blurs
static String getHexName(Color color)
          Return the hex name of a specified color.
static Map<RenderingHints.Key,Object> getHighQualityRenderingHints()
           
static ConvolveOp getLinearBlurOp(int size)
          Get a ConvolveOp that blurs
static Color HSLtoRGB(float h, float s, float l)
           Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.
static int[] HSLtoRGB(float h, float s, float l, int[] rgb)
           Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.
static BufferedImage invertColors(BufferedImage image)
          Invert the colors of an image
static boolean isDark(Color color)
          Check if a color is more dark than light.
static boolean isDark(double r, double g, double b)
          Check if a color is more dark than light.
static Color lighter(Color color, double fraction)
          Make a color lighter.
static BufferedImage makeColorTransparent(BufferedImage image, Color color)
          This method erases a color form an image with a completely transparency color and thus effectively erasing it Note: the image itself is altered, use createBufferedImage to work on a copy.
static void makeGlow(int[] pixels, int width, int height)
          Add a glow to an image http://www.curious-creature.org/2007/02/20/fast-image-processing-with-jogl Does not work at this time
static BufferedImage makeGray(BufferedImage image)
          make gray Note: the image itself is altered, use createBufferedImage to work on a copy.
static BufferedImage morph(BufferedImage from, BufferedImage to, double percentage)
           
static void paintReflectionImage(BufferedImage canvasImage, BufferedImage sourceImage, float compressionFactor, int offsetX, int offsetY)
          Paint the reflection onto the canvas
static BufferedImage putInPerspective(BufferedImage image)
           
static BufferedImage readThumbnailMaintainRatio(File imageFile, int maxWidth, int maxHeight)
          Read and create a thumbnail, maintaining ratio, without actually loading the original image in memory.
static BufferedImage removeMargin(BufferedImage image, int margin)
          This method is used to easy add a margin for blurring.
static BufferedImage replaceColor(BufferedImage image, Color originalColor, Color newColor)
          This method replace a color from an image with another color Note: the image itself is returned, use createBufferedImage to work on a copy.
static BufferedImage resize(BufferedImage image, double scale)
          Resize by scale
static BufferedImage resize(BufferedImage image, double scaleX, double scaleY)
          Resize by scale
static BufferedImage resize(BufferedImage image, int width, int height)
          Resize to W & H
static float[] RGBtoHSL(Color color)
           Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
static float[] RGBtoHSL(Color color, float[] hsl)
           Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
static float[] RGBtoHSL(int r, int g, int b)
           Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
static float[] RGBtoHSL(int r, int g, int b, float[] hsl)
           Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
static BufferedImage rotate90(BufferedImage image, boolean clockwise)
           
static BufferedImage textWithGlow(String text, Font font, int glowSize, Color foreground, Color glow, float opacity)
          Create an transparent image with glowing text
static BufferedImage watermark(BufferedImage image, BufferedImage watermarkImage, float impact)
           
static void writeJPG(BufferedImage image, File dstFile, float compressionQuality, boolean stripAlpha)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

HORIZONTAL

public static final int HORIZONTAL
See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
See Also:
Constant Field Values

DIAGONAL_LTBR

public static final int DIAGONAL_LTBR
See Also:
Constant Field Values

DIAGONAL_RTBL

public static final int DIAGONAL_RTBL
See Also:
Constant Field Values
Constructor Detail

ImageUtils

public ImageUtils()
Method Detail

createBufferedImage

public static BufferedImage createBufferedImage(int width,
                                                int height)
Although any BufferedImage can be painted, it is wise to created images that are compatible with the current screen device.


createBufferedImage

public static BufferedImage createBufferedImage(int width,
                                                int height,
                                                int transparency)
Although any BufferedImage can be painted, it is wise to created images that are compatible with the current screen device.

See Also:
Transparency

createEmptyBufferedImage

public static BufferedImage createEmptyBufferedImage(Image image)
Create a buffered image from a regular image


createJLabelImage

public static BufferedImage createJLabelImage(JLabel label,
                                              int margin,
                                              double blur)
Convert JLabel to Image

Parameters:
label - this labels contains the text, font, color (foreground) and contrast color (background)
margin -
blur - 0.5 is a good value

createJLabelImage

public static BufferedImage createJLabelImage(JLabel label,
                                              int margin,
                                              boolean blur)
Deprecated. use the method which has a double blur parameter


addText

public static void addText(BufferedImage image,
                           JLabel label)
Add a contrasted text to an image

Parameters:
image - image to add the text to
label - this labels contains the text, font, color (foreground) and contrast color (background)

addText

public static void addText(Graphics2D graphics2D,
                           double x,
                           double y,
                           TextLayout lTitle,
                           Color foreground,
                           Color background)
Draw a contrasted text

Parameters:
image - image to add the text to
label - this labels contains the text, font, color (foreground) and contrast color (background)

textWithGlow

public static BufferedImage textWithGlow(String text,
                                         Font font,
                                         int glowSize,
                                         Color foreground,
                                         Color glow,
                                         float opacity)
Create an transparent image with glowing text

Parameters:
text -
font -
glowSize -
foreground -
glow -
opacity -
Returns:

drawTextWithGlow

public static void drawTextWithGlow(String text,
                                    Graphics g,
                                    Font font,
                                    int glowSize,
                                    Color foreground,
                                    Color glow,
                                    float opacity)
Draw a glowing text on an image

Parameters:
text -
g -
font -
glowSize -
foreground -
glow -
opacity -

createGradientImage

public static BufferedImage createGradientImage(Color color1,
                                                Color color2,
                                                int direction)
Parameters:
color1 -
color2 -
direction -
Returns:

createGradientImage

public static BufferedImage createGradientImage(Color color1,
                                                Color color2,
                                                int direction,
                                                int width,
                                                int heigth)
Parameters:
color1 -
color2 -
direction -
width - of the to be generated image
height - of the to be generated image
Returns:

createGradientImage

public static BufferedImage createGradientImage(Color color1,
                                                Color color2,
                                                Color color3,
                                                int direction)
Parameters:
color1 -
color2 -
color3 -
direction -
Returns:

createGradientImage

public static BufferedImage createGradientImage(Color color1,
                                                Color color2,
                                                Color color3,
                                                int direction,
                                                int width,
                                                int height)
Parameters:
color1 -
color2 -
color3 -
direction -
width - of the to be generated image
height - of the to be generated image
Returns:

addNoise

public static BufferedImage addNoise(BufferedImage image)
add a bit of noise to the whole image

Parameters:
image - the image to add noise to
noiseFactor - how much noise should be added, something between 3.0 and 10.0 is usually a good value.

addNoise

public static BufferedImage addNoise(double noiseFactor,
                                     BufferedImage image)
add a bit of noise to the whole image

Parameters:
noiseFactor - how much noise should be added, something between 3.0 and 10.0 is usually a good value.
image - the image to add noise to

addNoise

public static BufferedImage addNoise(double noiseFactor,
                                     int x,
                                     int y,
                                     int width,
                                     int height,
                                     BufferedImage image)
add a bit of noise

Parameters:
noiseFactor - how much noise should be added, something between 3.0 and 10.0 is usually a good value.
x -
y -
width -
height -
image - the image to add noise to

addLinearBlur

public static BufferedImage addLinearBlur(BufferedImage image,
                                          int blurIndex)
Add a blur over the image (using linear blur). Please not that when the contents of the image is close to the edges, the blurring might cause strange side effects. Maintain a blur margin of about upto 20 pixels (depending on the blur radius). This blur uses ConvolveOp with a static (none Guassian) kernel


getLinearBlurOp

public static ConvolveOp getLinearBlurOp(int size)
Get a ConvolveOp that blurs

Parameters:
size -
Returns:

addGaussianBlur

public static BufferedImage addGaussianBlur(BufferedImage image,
                                            double radius)
Add a blur over the image (using linear blur). Please not that when the contents of the image is close to the edges, the blurring might cause strange side effects. Maintain a blur margin of about upto 20 pixels (depending on the blur radius). This blur uses ConvolveOp with a static (none Guassian) kernel


getGaussianBlurOp

public static ConvolveOp getGaussianBlurOp(double stddev)
Get a ConvolveOp that blurs

Parameters:
size -
Returns:

addBlur

public static BufferedImage addBlur(BufferedImage image)
Add a blur over the image (using GaussianBlur). Please note that when the contents of the image is close to the edges, the blurring might cause strange side effects. Maintain a blur margin of about upto 20 pixels (depending on the blur radius), see addMargin.


addMargin

public static BufferedImage addMargin(BufferedImage image,
                                      int margin)
This method is used to easy add a margin for blurring.


removeMargin

public static BufferedImage removeMargin(BufferedImage image,
                                         int margin)
This method is used to easy add a margin for blurring.


putInPerspective

public static BufferedImage putInPerspective(BufferedImage image)

paintReflectionImage

public static void paintReflectionImage(BufferedImage canvasImage,
                                        BufferedImage sourceImage,
                                        float compressionFactor,
                                        int offsetX,
                                        int offsetY)
Paint the reflection onto the canvas

Parameters:
canvasImage -
sourceImage -
compressionFactor -
offsetX -
offsetY -

createReflectionImage

public static BufferedImage createReflectionImage(BufferedImage image,
                                                  float compressionFactor)
Create a copy of the image with a reflection

Parameters:
image -
compressionFactor - how much of the original image is drawn as the reflection (2=half)
Returns:

createReflectionImage

public static BufferedImage createReflectionImage(BufferedImage image)

addReflectionImage

public static BufferedImage addReflectionImage(BufferedImage image,
                                               float compressionFactor,
                                               int reflectionOffset)
Create a copy of the image with a reflection

Parameters:
image -
compressionFactor - the amount with which the image is reduced (2 = half)
reflectionOffset - number of pixels the reflection is placed away from the original (0 is a good value)
Returns:

addReflectionImage

public static BufferedImage addReflectionImage(BufferedImage image)

flipVertical

public static BufferedImage flipVertical(BufferedImage image)
swap top and bottom


flipHorizontal

public static BufferedImage flipHorizontal(BufferedImage image)
swap left and right


rotate90

public static BufferedImage rotate90(BufferedImage image,
                                     boolean clockwise)

morph

public static BufferedImage morph(BufferedImage from,
                                  BufferedImage to,
                                  double percentage)

resize

public static BufferedImage resize(BufferedImage image,
                                   double scale)
Resize by scale


resize

public static BufferedImage resize(BufferedImage image,
                                   double scaleX,
                                   double scaleY)
Resize by scale


resize

public static BufferedImage resize(BufferedImage image,
                                   int width,
                                   int height)
Resize to W & H

Parameters:
image -
width -
height -
Returns:

makeGlow

public static void makeGlow(int[] pixels,
                            int width,
                            int height)
Add a glow to an image http://www.curious-creature.org/2007/02/20/fast-image-processing-with-jogl Does not work at this time


createBufferedImage

public static BufferedImage createBufferedImage(Image image)
Create a buffered image from a regular image


getHighQualityRenderingHints

public static Map<RenderingHints.Key,Object> getHighQualityRenderingHints()
Returns:

createImageFromComponent

public static BufferedImage createImageFromComponent(Component component)
Create a buffered image from a component

Parameters:
component - Component
Returns:
BufferedImage

createImageFromIcon

public static BufferedImage createImageFromIcon(Icon icon)
Create a buffered image from a component

Parameters:
icon - Component
Returns:
BufferedImage

createPixels

public static int[] createPixels(BufferedImage bufferedImage)
Convert a buffered image into an array of rows of pixels The grabPixels method of the PixelGrabber class extracts the pixel data from an Image object into a one-dimensional array of type int. Each element in the array contains the four unsigned data bytes that represent a single pixel. The most significant byte contains the alpha or transparency data. Moving from most to least significant, the remaining bytes contain the unsigned values for red, green, and blue. If the image has N columns of pixels in each row, the first N elements in the array contain the data for the first row; the second N elements contain the data for the second row, etc.

Parameters:
bufferedImage -
Returns:

createImage

public static Image createImage(int[] pixels,
                                int width,
                                int height)
Create image from pixels

Parameters:
pixels -
width -
height -
Returns:

captureScreen

public static BufferedImage captureScreen()
Capture the current screen


readThumbnailMaintainRatio

public static BufferedImage readThumbnailMaintainRatio(File imageFile,
                                                       int maxWidth,
                                                       int maxHeight)
                                                throws IOException
Read and create a thumbnail, maintaining ratio, without actually loading the original image in memory. Reading large images into memory and then scaling to create a thumbnail may cause memory problems and be slow. This method creates a thumbnail image by streaming the original image (not loading it into memory) and taking every Nth pixel from the original.

Parameters:
imageFile -
maxWidth -
maxHeight -
Returns:
Throws:
IOException

writeJPG

public static void writeJPG(BufferedImage image,
                            File dstFile,
                            float compressionQuality,
                            boolean stripAlpha)
                     throws IOException
Parameters:
image -
type -
dstFile -
compressionQuality - [0.0 .. 1.0]
stripAlpha -
Throws:
IOException

watermark

public static BufferedImage watermark(BufferedImage image,
                                      BufferedImage watermarkImage,
                                      float impact)

replaceColor

public static BufferedImage replaceColor(BufferedImage image,
                                         Color originalColor,
                                         Color newColor)
This method replace a color from an image with another color Note: the image itself is returned, use createBufferedImage to work on a copy.


makeColorTransparent

public static BufferedImage makeColorTransparent(BufferedImage image,
                                                 Color color)
This method erases a color form an image with a completely transparency color and thus effectively erasing it Note: the image itself is altered, use createBufferedImage to work on a copy.


clear

public static BufferedImage clear(BufferedImage bufferedImage)

makeGray

public static BufferedImage makeGray(BufferedImage image)
make gray Note: the image itself is altered, use createBufferedImage to work on a copy.


createDisabled

public static Image createDisabled(BufferedImage image)
Return a new image that appears disabled

Parameters:
image -
Returns:

brighter

public static BufferedImage brighter(BufferedImage image,
                                     int times)
make brigher Note: the image itself is altered, use createBufferedImage to work on a copy.


brighter

public static BufferedImage brighter(BufferedImage image)

darker

public static BufferedImage darker(BufferedImage image)
make darker Note: the image itself is altered, use createBufferedImage to work on a copy.


createShadedImage

public static BufferedImage createShadedImage(BufferedImage image,
                                              boolean addShade)
Create a copy of the image with or without a shadow (beware: this is not a DROP shadow, but an actual image).

Parameters:
image -
addShade -
Returns:

createShadedImage

public static BufferedImage createShadedImage(BufferedImage image,
                                              int shadeOffset)
Create a copy of the image with a shadow (beware: this is not a DROP shadow, but an actual image).

Parameters:
image -
shadeOffset -
Returns:

brightnessFactor

public static double brightnessFactor(BufferedImage image)
calculate a factor for the image's overall brightness


invertColors

public static BufferedImage invertColors(BufferedImage image)
Invert the colors of an image

Parameters:
image -
Returns:

applySepiaFilter

public static void applySepiaFilter(BufferedImage img,
                                    int sepiaIntensity)
                             throws Exception
http://www.rhinocerus.net/forum/lang-java-programmer/574119-sepia-tone-image-filter-java.html

Parameters:
img - Image to modify
sepiaIntensity - From 0-255, 30 produces nice results
Throws:
Exception

blend

public static Color blend(Color color1,
                          Color color2,
                          double ratio)
Blend two colors.

Parameters:
color1 - First color to blend.
color2 - Second color to blend.
ratio - Blend ratio. 0.5 will give even blend, 1.0 will return color1, 0.0 will return color2 and so on.
Returns:
Blended color.

blend

public static Color blend(Color color1,
                          Color color2)
Make an even blend between two colors.

Parameters:
c1 - First color to blend.
c2 - Second color to blend.
Returns:
Blended color.

darker

public static Color darker(Color color,
                           double fraction)
Make a color darker.

Parameters:
color - Color to make darker.
fraction - Darkness fraction.
Returns:
Darker color.

lighter

public static Color lighter(Color color,
                            double fraction)
Make a color lighter.

Parameters:
color - Color to make lighter.
fraction - Darkness fraction.
Returns:
Lighter color.

getHexName

public static String getHexName(Color color)
Return the hex name of a specified color.

Parameters:
color - Color to get hex name of.
Returns:
Hex name of color: "rrggbb".

colorDistance

public static double colorDistance(double r1,
                                   double g1,
                                   double b1,
                                   double r2,
                                   double g2,
                                   double b2)
Return the "distance" between two colors. The rgb entries are taken to be coordinates in a 3D space [0.0-1.0], and this method returnes the distance between the coordinates for the first and second color.

Parameters:
r1 - , g1, b1 First color.
r2 - , g2, b2 Second color.
Returns:
Distance bwetween colors.

colorDistance

public static double colorDistance(double[] color1,
                                   double[] color2)
Return the "distance" between two colors.

Parameters:
color1 - First color [r,g,b].
color2 - Second color [r,g,b].
Returns:
Distance bwetween colors.

colorDistance

public static double colorDistance(Color color1,
                                   Color color2)
Return the "distance" between two colors.

Parameters:
color1 - First color.
color2 - Second color.
Returns:
Distance between colors.

isDark

public static boolean isDark(double r,
                             double g,
                             double b)
Check if a color is more dark than light. Useful if an entity of this color is to be labeled: Use white label on a "dark" color and black label on a "light" color.

Parameters:
r - ,g,b Color to check.
Returns:
True if this is a "dark" color, false otherwise.

isDark

public static boolean isDark(Color color)
Check if a color is more dark than light. Useful if an entity of this color is to be labeled: Use white label on a "dark" color and black label on a "light" color.

Parameters:
color - Color to check.
Returns:
True if this is a "dark" color, false otherwise.

RGBtoHSL

public static float[] RGBtoHSL(Color color)

Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are between 0.0 and 1.0.

Parameters:
color - the RGB color to convert
Returns:
a new array of 3 floats corresponding to the HSL components

RGBtoHSL

public static float[] RGBtoHSL(Color color,
                               float[] hsl)

Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are between 0.0 and 1.0.

Parameters:
color - the RGB color to convert
hsl - a pre-allocated array of floats; can be null
Returns:
hsl if non-null, a new array of 3 floats otherwise
Throws:
IllegalArgumentException - if hsl has a length lower than 3

RGBtoHSL

public static float[] RGBtoHSL(int r,
                               int g,
                               int b)

Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are between 0.0 and 1.0.

Parameters:
r - the red component, between 0 and 255
g - the green component, between 0 and 255
b - the blue component, between 0 and 255
Returns:
a new array of 3 floats corresponding to the HSL components

RGBtoHSL

public static float[] RGBtoHSL(int r,
                               int g,
                               int b,
                               float[] hsl)

Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are floats between 0.0 and 1.0.

Parameters:
r - the red component, between 0 and 255
g - the green component, between 0 and 255
b - the blue component, between 0 and 255
hsl - a pre-allocated array of floats; can be null
Returns:
hsl if non-null, a new array of 3 floats otherwise
Throws:
IllegalArgumentException - if hsl has a length lower than 3

HSLtoRGB

public static Color HSLtoRGB(float h,
                             float s,
                             float l)

Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.

Parameters:
h - the hue component, between 0.0 and 1.0
s - the saturation component, between 0.0 and 1.0
l - the luminance component, between 0.0 and 1.0
Returns:
a new Color object equivalent to the HSL components

HSLtoRGB

public static int[] HSLtoRGB(float h,
                             float s,
                             float l,
                             int[] rgb)

Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color. All three RGB components are integers between 0 and 255.

Parameters:
h - the hue component, between 0.0 and 1.0
s - the saturation component, between 0.0 and 1.0
l - the luminance component, between 0.0 and 1.0
rgb - a pre-allocated array of ints; can be null
Returns:
rgb if non-null, a new array of 3 ints otherwise
Throws:
IllegalArgumentException - if rgb has a length lower than 3


Copyright © 2011 KnowledgePlaza. All Rights Reserved.