public class ImageUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static boolean |
debug
debug flag
|
Constructor and Description |
---|
ImageUtils() |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
clip(java.awt.image.BufferedImage image,
int[] ul,
int[] lr)
Clip the image
|
static java.lang.String |
convertImageTo(java.lang.String file,
java.lang.String newType)
Convert an image to a new type
|
static int |
getColumnCountFromComps(java.util.List<? extends java.awt.Component> views)
Gets the column count from the components.
|
static javax.swing.JEditorPane |
getEditor(javax.swing.JEditorPane editor,
java.lang.String html,
int width,
java.awt.Color transparentColor,
java.awt.Font font)
Make a editor pane from the html
|
static javax.swing.JEditorPane |
getEditor(java.lang.String html,
int width,
java.awt.Color transparentColor,
java.awt.Font font)
Make a editor pane from the html
|
static java.awt.Image |
getImage(java.awt.Component component)
Get the screen image from the component
|
static java.awt.Image |
getImage(javax.swing.JEditorPane editor,
java.awt.Color transparentColor)
Get an image from the component
|
static java.awt.Image |
getImageFile(java.lang.String file)
Read in the image from the given filename or url
|
static java.awt.Image |
gridImages(java.util.List images,
int space,
java.awt.Color bg,
int columns)
Merge images
|
static java.awt.Image |
gridImages2(java.util.List<? extends java.awt.Image> images,
int space,
java.awt.Color bg,
int columns)
Merge Images.
|
static boolean |
hasAlpha(java.awt.Image image)
Check to see if the image has alpha
|
static java.awt.image.BufferedImage |
horizontalflip(java.awt.image.BufferedImage img)
Flip the image horizontally
From: Josiah Hester - http://www.javalobby.org/articles/ultimate-image
|
static boolean |
isImage(java.lang.String file)
Is the file name an image
|
static void |
main(java.lang.String[] args)
Read in the image.
|
static java.awt.image.BufferedImage |
makeColorTransparent(java.awt.Image im,
java.awt.Color c)
Make a color in the image transparent
|
static java.awt.image.BufferedImage |
makeColorTransparent(java.awt.Image im,
int[] redRange,
int[] greenRange,
int[] blueRange)
Set the colors taht are within the given red, green and blue ranges to be transparent.
|
static java.awt.image.BufferedImage |
matte(java.awt.image.BufferedImage image,
int top,
int bottom,
int left,
int right,
java.awt.Color bg)
Add a matte border around the image
|
static java.awt.Image |
mergeHorizontal(java.util.List<? extends java.awt.Image> images)
Merge the images horizontally.
|
static java.awt.Image |
mergeImages(java.util.List images,
int space,
java.awt.Color bg)
Merge images
|
static java.awt.Image |
mergeVertical(java.util.List<? extends java.awt.Image> images)
Merge the images vertically.
|
static java.awt.Image |
padImage(java.awt.Image image,
int space,
java.awt.Color color)
Pad the image.
|
static java.awt.Point |
parsePoint(java.lang.String s,
java.awt.Rectangle r)
Parse the string specification of a point with respect to the rectangle.
|
static java.awt.Image |
readImage(java.lang.String imagePath)
Read and image
|
static java.awt.Image |
readImage(java.lang.String imagePath,
boolean cache)
Read and image
|
static java.awt.Image |
readImage(java.lang.String imagePath,
boolean cache,
boolean returnNullIfNotFound)
Read and image
|
static java.awt.image.BufferedImage |
removeRedeye(java.awt.Image im,
int x1,
int y1,
int x2,
int y2)
Remove the brighter red from the image
|
static java.awt.Image |
renderHtml(java.lang.String html,
int width,
java.awt.Color transparentColor,
java.awt.Font font)
Render the given html and return an image
|
static java.awt.Image |
resize(java.awt.Image image,
int width,
int height)
Resize an image
|
static java.awt.image.BufferedImage |
rotate90(java.awt.image.BufferedImage img,
boolean left)
Rotate the image 90 degrees
|
static java.awt.image.BufferedImage |
setAlpha(java.awt.Image im,
double percent)
Set the alpha channel to the given transparency percent
|
static int |
toAlpha(double percent)
Change the transparency percentage into an int alpha value
|
static java.awt.image.BufferedImage |
toBufferedImage(java.awt.Image image)
This method returns a buffered image with the contents of an image
|
static java.awt.image.BufferedImage |
toBufferedImage(java.awt.Image image,
boolean force)
This method returns a buffered image with the contents of an image
|
static java.awt.image.BufferedImage |
toBufferedImage(java.awt.Image image,
int type)
Create a BufferedImage from the given image
|
static java.awt.Point |
toPoint(java.awt.geom.Point2D p)
convenience to convert to a Point
|
static java.awt.image.BufferedImage |
verticalflip(java.awt.image.BufferedImage img)
Flip the image vertically
From: Josiah Hester - http://www.javalobby.org/articles/ultimate-image
|
static java.awt.Image |
waitOnImage(java.awt.Image image)
Wait until it is loaded in.
|
static void |
writeAvi(java.util.List imageFiles,
double frameRateInFPS,
java.io.File outFile)
Write an AVI file
|
static boolean |
writeImage(javax.swing.JDialog window,
java.lang.String file)
Make a screen capture of the window.
|
static boolean |
writeImage(javax.swing.JFrame window,
java.lang.String file)
Make a screen capture of the window.
|
static void |
writeImageToFile(java.awt.Component component,
java.lang.String saveFile)
Take a screen snapshot of the component.
|
static void |
writeImageToFile(java.awt.Image image,
java.io.File saveFile)
Write a Buffered image to a file
|
static void |
writeImageToFile(java.awt.Image image,
java.lang.String saveFile)
Write a Buffered image to a file
|
static void |
writeImageToFile(java.awt.Image image,
java.lang.String saveFile,
float quality)
Write a Buffered image to a file at a particular quality
|
static void |
writeImageToFile(java.awt.Image image,
java.lang.String saveFile,
java.io.OutputStream os,
float quality)
Write a Buffered image to a file at a particular quality
|
static void |
writePDF(java.io.OutputStream out,
javax.swing.JComponent comp)
test code
|
public static java.awt.image.BufferedImage matte(java.awt.image.BufferedImage image, int top, int bottom, int left, int right, java.awt.Color bg)
image
- The imagetop
- top spacebottom
- bottom spaceleft
- left spaceright
- right spacebg
- Background colorpublic static java.awt.image.BufferedImage clip(java.awt.image.BufferedImage image, int[] ul, int[] lr)
image
- The imageul
- upper leftlr
- lower rightpublic static java.awt.Image readImage(java.lang.String imagePath)
imagePath
- the path to the imagepublic static java.awt.Image readImage(java.lang.String imagePath, boolean cache)
imagePath
- the path to the imagecache
- Cache the imagepublic static java.awt.Image readImage(java.lang.String imagePath, boolean cache, boolean returnNullIfNotFound)
imagePath
- the path to the imagecache
- Cache the imagereturnNullIfNotFound
- if true, return null if the image does not existpublic static java.awt.Image waitOnImage(java.awt.Image image)
image
- the imagepublic static java.awt.image.BufferedImage makeColorTransparent(java.awt.Image im, java.awt.Color c)
im
- imagec
- the color to make transparentpublic static java.awt.image.BufferedImage makeColorTransparent(java.awt.Image im, int[] redRange, int[] greenRange, int[] blueRange)
im
- The imageredRange
- red rangegreenRange
- green rangeblueRange
- blue rangepublic static java.awt.image.BufferedImage removeRedeye(java.awt.Image im, int x1, int y1, int x2, int y2)
im
- imagex1
- boundsy1
- boundsx2
- boundsy2
- boundspublic static int toAlpha(double percent)
percent
- the percent transparent 0-1.0public static java.awt.image.BufferedImage setAlpha(java.awt.Image im, double percent)
im
- imagepercent
- Percent transparent 0-1.0public static java.awt.Point toPoint(java.awt.geom.Point2D p)
p
- pointpublic static java.awt.Point parsePoint(java.lang.String s, java.awt.Rectangle r)
ul um ur ml mm mr ll lm lrWhere u=upper,m=middle,l=lower r=right,l=left
s
- String specificationr
- Reference rectanglepublic static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image)
image
- the imagepublic static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image, boolean force)
image
- the imageforce
- If false then just return the image argument if its a BufferedImagepublic static java.awt.Image mergeImages(java.util.List images, int space, java.awt.Color bg)
images
- list of imagesspace
- space between imagesbg
- background colorpublic static java.awt.Image gridImages(java.util.List images, int space, java.awt.Color bg, int columns)
images
- list of imagesspace
- space between imagesbg
- background colorcolumns
- number of columnspublic static java.awt.Image gridImages2(java.util.List<? extends java.awt.Image> images, int space, java.awt.Color bg, int columns)
gridImages(List, int, Color, int)
so the results can be
different.images
- the images that will be griddedspace
- the space padding around each image.bg
- the background color "behind" the image.columns
- how many columns in the gridpublic static java.awt.Image padImage(java.awt.Image image, int space, java.awt.Color color)
image
- the imagespace
- the spacecolor
- the colorpublic static java.awt.Image mergeHorizontal(java.util.List<? extends java.awt.Image> images)
images
- the imagespublic static java.awt.Image mergeVertical(java.util.List<? extends java.awt.Image> images)
images
- the imagespublic static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image, int type)
image
- The imagetype
- BufferedImage typepublic static boolean hasAlpha(java.awt.Image image)
image
- the imagepublic static java.awt.Image getImage(java.awt.Component component) throws java.lang.Exception
component
- The component.java.lang.Exception
public static void writeImageToFile(java.awt.Image image, java.io.File saveFile) throws java.lang.Exception
image
- image to writesaveFile
- file to write tojava.lang.Exception
- problem writing filepublic static void writeImageToFile(java.awt.Image image, java.lang.String saveFile) throws java.lang.Exception
image
- image to writesaveFile
- file to write tojava.lang.Exception
- problem writing filepublic static java.awt.image.BufferedImage horizontalflip(java.awt.image.BufferedImage img)
img
- imagepublic static java.awt.image.BufferedImage verticalflip(java.awt.image.BufferedImage img)
img
- imagepublic static java.awt.image.BufferedImage rotate90(java.awt.image.BufferedImage img, boolean left)
img
- imageleft
- rotate counter clockwisepublic static java.lang.String convertImageTo(java.lang.String file, java.lang.String newType)
file
- image filenewType
- new image typepublic static void writeImageToFile(java.awt.Image image, java.lang.String saveFile, float quality) throws java.lang.Exception
image
- image to writesaveFile
- file to write toquality
- image quality (if supported)java.lang.Exception
- problem writing filepublic static void writeImageToFile(java.awt.Image image, java.lang.String saveFile, java.io.OutputStream os, float quality) throws java.lang.Exception
image
- image to writesaveFile
- _more_os
- output streamquality
- image quality (if supported)java.lang.Exception
- problem writing filepublic static boolean isImage(java.lang.String file)
file
- filepublic static boolean writeImage(javax.swing.JDialog window, java.lang.String file) throws java.lang.Exception
window
- The windowfile
- The filejava.lang.Exception
public static boolean writeImage(javax.swing.JFrame window, java.lang.String file) throws java.lang.Exception
window
- The windowfile
- The filejava.lang.Exception
public static void writeImageToFile(java.awt.Component component, java.lang.String saveFile) throws java.lang.Exception
component
- The component.saveFile
- The file.java.lang.Exception
public static void writeAvi(java.util.List imageFiles, double frameRateInFPS, java.io.File outFile) throws java.io.IOException
imageFiles
- list of filesframeRateInFPS
- frame rateoutFile
- output filejava.io.IOException
- problem writing AVIpublic static java.awt.Image resize(java.awt.Image image, int width, int height)
image
- the imagewidth
- new widthheight
- new heightpublic static java.awt.Image getImage(javax.swing.JEditorPane editor, java.awt.Color transparentColor) throws java.lang.Exception
editor
- componenttransparentColor
- if non null then set this color to be transparentjava.lang.Exception
- on badnesspublic static java.awt.Image renderHtml(java.lang.String html, int width, java.awt.Color transparentColor, java.awt.Font font) throws java.lang.Exception
html
- html to renderwidth
- image widthtransparentColor
- if non null set this color in the image to be transparentfont
- font to render withjava.lang.Exception
- on badnesspublic static javax.swing.JEditorPane getEditor(java.lang.String html, int width, java.awt.Color transparentColor, java.awt.Font font) throws java.lang.Exception
html
- htmlwidth
- widthtransparentColor
- what color to set as transparentfont
- fontjava.lang.Exception
- on badnesspublic static javax.swing.JEditorPane getEditor(javax.swing.JEditorPane editor, java.lang.String html, int width, java.awt.Color transparentColor, java.awt.Font font) throws java.lang.Exception
editor
- Initial editorhtml
- htmlwidth
- widthtransparentColor
- what color to set as transparentfont
- fontjava.lang.Exception
- on badnesspublic static void writePDF(java.io.OutputStream out, javax.swing.JComponent comp) throws java.io.IOException
out
- testcomp
- testjava.io.IOException
- testpublic static void main(java.lang.String[] args) throws java.lang.Exception
args
- argsjava.lang.Exception
- problem with thispublic static java.awt.Image getImageFile(java.lang.String file) throws java.lang.Exception
file
- File or urljava.lang.Exception
- On badnesspublic static int getColumnCountFromComps(java.util.List<? extends java.awt.Component> views)
views
- the views