|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnl.knowledgeplaza.util.ImageUtils
org.tbee.swing.ImageUtils
public class 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.
| 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 |
|---|
public static final String SOURCECODE_VERSION
public static final int HORIZONTAL
public static final int VERTICAL
public static final int DIAGONAL_LTBR
public static final int DIAGONAL_RTBL
| Constructor Detail |
|---|
public ImageUtils()
| Method Detail |
|---|
public static BufferedImage createBufferedImage(int width,
int height)
public static BufferedImage createBufferedImage(int width,
int height,
int transparency)
Transparencypublic static BufferedImage createEmptyBufferedImage(Image image)
public static BufferedImage createJLabelImage(JLabel label,
int margin,
double blur)
label - this labels contains the text, font, color (foreground) and contrast color (background)margin - blur - 0.5 is a good value
public static BufferedImage createJLabelImage(JLabel label,
int margin,
boolean blur)
public static void addText(BufferedImage image,
JLabel label)
image - image to add the text tolabel - this labels contains the text, font, color (foreground) and
contrast color (background)
public static void addText(Graphics2D graphics2D,
double x,
double y,
TextLayout lTitle,
Color foreground,
Color background)
image - image to add the text tolabel - this labels contains the text, font, color (foreground) and
contrast color (background)
public static BufferedImage textWithGlow(String text,
Font font,
int glowSize,
Color foreground,
Color glow,
float opacity)
text - font - glowSize - foreground - glow - opacity -
public static void drawTextWithGlow(String text,
Graphics g,
Font font,
int glowSize,
Color foreground,
Color glow,
float opacity)
text - g - font - glowSize - foreground - glow - opacity -
public static BufferedImage createGradientImage(Color color1,
Color color2,
int direction)
color1 - color2 - direction -
public static BufferedImage createGradientImage(Color color1,
Color color2,
int direction,
int width,
int heigth)
color1 - color2 - direction - width - of the to be generated imageheight - of the to be generated image
public static BufferedImage createGradientImage(Color color1,
Color color2,
Color color3,
int direction)
color1 - color2 - color3 - direction -
public static BufferedImage createGradientImage(Color color1,
Color color2,
Color color3,
int direction,
int width,
int height)
color1 - color2 - color3 - direction - width - of the to be generated imageheight - of the to be generated image
public static BufferedImage addNoise(BufferedImage image)
image - the image to add noise tonoiseFactor - how much noise should be added, something between 3.0 and 10.0 is usually a good value.
public static BufferedImage addNoise(double noiseFactor,
BufferedImage image)
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
public static BufferedImage addNoise(double noiseFactor,
int x,
int y,
int width,
int height,
BufferedImage image)
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
public static BufferedImage addLinearBlur(BufferedImage image,
int blurIndex)
public static ConvolveOp getLinearBlurOp(int size)
size -
public static BufferedImage addGaussianBlur(BufferedImage image,
double radius)
public static ConvolveOp getGaussianBlurOp(double stddev)
size -
public static BufferedImage addBlur(BufferedImage image)
public static BufferedImage addMargin(BufferedImage image,
int margin)
public static BufferedImage removeMargin(BufferedImage image,
int margin)
public static BufferedImage putInPerspective(BufferedImage image)
public static void paintReflectionImage(BufferedImage canvasImage,
BufferedImage sourceImage,
float compressionFactor,
int offsetX,
int offsetY)
canvasImage - sourceImage - compressionFactor - offsetX - offsetY -
public static BufferedImage createReflectionImage(BufferedImage image,
float compressionFactor)
image - compressionFactor - how much of the original image is drawn as the reflection (2=half)
public static BufferedImage createReflectionImage(BufferedImage image)
public static BufferedImage addReflectionImage(BufferedImage image,
float compressionFactor,
int reflectionOffset)
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)
public static BufferedImage addReflectionImage(BufferedImage image)
public static BufferedImage flipVertical(BufferedImage image)
public static BufferedImage flipHorizontal(BufferedImage image)
public static BufferedImage rotate90(BufferedImage image,
boolean clockwise)
public static BufferedImage morph(BufferedImage from,
BufferedImage to,
double percentage)
public static BufferedImage resize(BufferedImage image,
double scale)
public static BufferedImage resize(BufferedImage image,
double scaleX,
double scaleY)
public static BufferedImage resize(BufferedImage image,
int width,
int height)
image - width - height -
public static void makeGlow(int[] pixels,
int width,
int height)
public static BufferedImage createBufferedImage(Image image)
public static Map<RenderingHints.Key,Object> getHighQualityRenderingHints()
public static BufferedImage createImageFromComponent(Component component)
component - Component
public static BufferedImage createImageFromIcon(Icon icon)
icon - Component
public static int[] createPixels(BufferedImage bufferedImage)
bufferedImage -
public static Image createImage(int[] pixels,
int width,
int height)
pixels - width - height -
public static BufferedImage captureScreen()
public static BufferedImage readThumbnailMaintainRatio(File imageFile,
int maxWidth,
int maxHeight)
throws IOException
imageFile - maxWidth - maxHeight -
IOException
public static void writeJPG(BufferedImage image,
File dstFile,
float compressionQuality,
boolean stripAlpha)
throws IOException
image - type - dstFile - compressionQuality - [0.0 .. 1.0]stripAlpha -
IOException
public static BufferedImage watermark(BufferedImage image,
BufferedImage watermarkImage,
float impact)
public static BufferedImage replaceColor(BufferedImage image,
Color originalColor,
Color newColor)
public static BufferedImage makeColorTransparent(BufferedImage image,
Color color)
public static BufferedImage clear(BufferedImage bufferedImage)
public static BufferedImage makeGray(BufferedImage image)
public static Image createDisabled(BufferedImage image)
image -
public static BufferedImage brighter(BufferedImage image,
int times)
public static BufferedImage brighter(BufferedImage image)
public static BufferedImage darker(BufferedImage image)
public static BufferedImage createShadedImage(BufferedImage image,
boolean addShade)
image - addShade -
public static BufferedImage createShadedImage(BufferedImage image,
int shadeOffset)
image - shadeOffset -
public static double brightnessFactor(BufferedImage image)
public static BufferedImage invertColors(BufferedImage image)
image -
public static void applySepiaFilter(BufferedImage img,
int sepiaIntensity)
throws Exception
img - Image to modifysepiaIntensity - From 0-255, 30 produces nice results
Exception
public static Color blend(Color color1,
Color color2,
double ratio)
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.
public static Color blend(Color color1,
Color color2)
c1 - First color to blend.c2 - Second color to blend.
public static Color darker(Color color,
double fraction)
color - Color to make darker.fraction - Darkness fraction.
public static Color lighter(Color color,
double fraction)
color - Color to make lighter.fraction - Darkness fraction.
public static String getHexName(Color color)
color - Color to get hex name of.
public static double colorDistance(double r1,
double g1,
double b1,
double r2,
double g2,
double b2)
r1 - , g1, b1 First color.r2 - , g2, b2 Second color.
public static double colorDistance(double[] color1,
double[] color2)
color1 - First color [r,g,b].color2 - Second color [r,g,b].
public static double colorDistance(Color color1,
Color color2)
color1 - First color.color2 - Second color.
public static boolean isDark(double r,
double g,
double b)
r - ,g,b Color to check.
public static boolean isDark(Color color)
color - Color to check.
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.
color - the RGB color to convert
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.
color - the RGB color to converthsl - a pre-allocated array of floats; can be null
hsl if non-null, a new array of 3 floats otherwise
IllegalArgumentException - if hsl has a length lower than 3
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.
r - the red component, between 0 and 255g - the green component, between 0 and 255b - the blue component, between 0 and 255
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.
r - the red component, between 0 and 255g - the green component, between 0 and 255b - the blue component, between 0 and 255hsl - a pre-allocated array of floats; can be null
hsl if non-null, a new array of 3 floats otherwise
IllegalArgumentException - if hsl has a length lower than 3
public static Color HSLtoRGB(float h,
float s,
float l)
Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.
h - the hue component, between 0.0 and 1.0s - the saturation component, between 0.0 and 1.0l - the luminance component, between 0.0 and 1.0
Color object equivalent to the HSL components
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.
h - the hue component, between 0.0 and 1.0s - the saturation component, between 0.0 and 1.0l - the luminance component, between 0.0 and 1.0rgb - a pre-allocated array of ints; can be null
rgb if non-null, a new array of 3 ints otherwise
IllegalArgumentException - if rgb has a length lower than 3
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||