Package ucar.unidata.ui
Class ImageUtils
java.lang.Object
ucar.unidata.ui.ImageUtils
Provides a set of image manipulation utilities
- Author:
- IDV development team
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageclip(BufferedImage image, int[] ul, int[] lr) Clip the imagestatic StringconvertImageTo(String file, String newType) Convert an image to a new typestatic intgetColumnCountFromComps(List<? extends Component> views) Gets the column count from the components.static JEditorPaneMake a editor pane from the htmlstatic JEditorPanegetEditor(JEditorPane editor, String html, int width, Color transparentColor, Font font) Make a editor pane from the htmlstatic ImageGet the screen image from the componentstatic ImagegetImage(JEditorPane editor, Color transparentColor) Get an image from the componentstatic ImagegetImageFile(String file) Read in the image from the given filename or urlstatic ImagegridImages(List images, int space, Color bg, int columns) Merge imagesstatic ImagegridImages2(List<? extends Image> images, int space, Color bg, int columns) Merge Images.static booleanCheck to see if the image has alphastatic BufferedImageFlip the image horizontally From: Josiah Hester - http://www.javalobby.org/articles/ultimate-imagestatic booleanIs the file name an imagestatic voidRead in the image.static BufferedImagemakeColorTransparent(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 BufferedImagemakeColorTransparent(Image im, Color c) Make a color in the image transparentstatic BufferedImagematte(BufferedImage image, int top, int bottom, int left, int right, Color bg) Add a matte border around the imagestatic ImagemergeHorizontal(List<? extends Image> images) Merge the images horizontally.static ImagemergeImages(List images, int space, Color bg) Merge imagesstatic ImagemergeVertical(List<? extends Image> images) Merge the images vertically.static ImagePad the image.static PointparsePoint(String s, Rectangle r) Parse the string specification of a point with respect to the rectangle.static ImageRead and imagestatic ImageRead and imagestatic ImageRead and imagestatic BufferedImageremoveRedeye(Image im, int x1, int y1, int x2, int y2) Remove the brighter red from the imagestatic ImagerenderHtml(String html, int width, Color transparentColor, Font font) Render the given html and return an imagestatic ImageResize an imagestatic BufferedImagerotate90(BufferedImage img, boolean left) Rotate the image 90 degreesstatic BufferedImageSet the alpha channel to the given transparency percentstatic inttoAlpha(double percent) Change the transparency percentage into an int alpha valuestatic BufferedImagetoBufferedImage(Image image) This method returns a buffered image with the contents of an imagestatic BufferedImagetoBufferedImage(Image image, boolean force) This method returns a buffered image with the contents of an imagestatic BufferedImagetoBufferedImage(Image image, int type) Create a BufferedImage from the given imagestatic Pointconvenience to convert to a Pointstatic BufferedImageFlip the image vertically From: Josiah Hester - http://www.javalobby.org/articles/ultimate-imagestatic ImagewaitOnImage(Image image) Wait until it is loaded in.static voidWrite an AVI filestatic booleanwriteImage(JDialog window, String file) Make a screen capture of the window.static booleanwriteImage(JFrame window, String file) Make a screen capture of the window.static voidwriteImageToFile(Component component, String saveFile) Take a screen snapshot of the component.static voidwriteImageToFile(Image image, File saveFile) Write a Buffered image to a filestatic voidwriteImageToFile(Image image, String saveFile) Write a Buffered image to a filestatic voidwriteImageToFile(Image image, String saveFile, float quality) Write a Buffered image to a file at a particular qualitystatic voidwriteImageToFile(Image image, String saveFile, OutputStream os, float quality) Write a Buffered image to a file at a particular qualitystatic voidwritePDF(OutputStream out, JComponent comp) test code
-
Field Details
-
debug
public static boolean debugdebug flag
-
-
Constructor Details
-
ImageUtils
public ImageUtils()
-
-
Method Details
-
matte
public static BufferedImage matte(BufferedImage image, int top, int bottom, int left, int right, Color bg) Add a matte border around the image- Parameters:
image- The imagetop- top spacebottom- bottom spaceleft- left spaceright- right spacebg- Background color- Returns:
- The matted image
-
clip
Clip the image- Parameters:
image- The imageul- upper leftlr- lower right- Returns:
- The clipped image
-
readImage
Read and image- Parameters:
imagePath- the path to the image- Returns:
- the Image
-
readImage
Read and image- Parameters:
imagePath- the path to the imagecache- Cache the image- Returns:
- the Image
-
readImage
Read and image- Parameters:
imagePath- the path to the imagecache- Cache the imagereturnNullIfNotFound- if true, return null if the image does not exist- Returns:
- the Image
-
waitOnImage
Wait until it is loaded in.- Parameters:
image- the image- Returns:
- The image
-
makeColorTransparent
Make a color in the image transparent- Parameters:
im- imagec- the color to make transparent- Returns:
- a new image with the color transparent.
-
makeColorTransparent
public static BufferedImage makeColorTransparent(Image im, int[] redRange, int[] greenRange, int[] blueRange) Set the colors taht are within the given red, green and blue ranges to be transparent.- Parameters:
im- The imageredRange- red rangegreenRange- green rangeblueRange- blue range- Returns:
- munged image
-
removeRedeye
Remove the brighter red from the image- Parameters:
im- imagex1- boundsy1- boundsx2- boundsy2- bounds- Returns:
- new image
-
toAlpha
public static int toAlpha(double percent) Change the transparency percentage into an int alpha value- Parameters:
percent- the percent transparent 0-1.0- Returns:
- the alpha value
-
setAlpha
Set the alpha channel to the given transparency percent- Parameters:
im- imagepercent- Percent transparent 0-1.0- Returns:
- munged image
-
toPoint
convenience to convert to a Point- Parameters:
p- point- Returns:
- point
-
parsePoint
Parse the string specification of a point with respect to the rectangle. The spec can look like: "rectpoint,offsetx,offsety" where rectpoint can be:ul um ur ml mm mr ll lm lr
Where u=upper,m=middle,l=lower r=right,l=left- Parameters:
s- String specificationr- Reference rectangle- Returns:
- The point
-
toBufferedImage
This method returns a buffered image with the contents of an image- Parameters:
image- the image- Returns:
- a buffered image
-
toBufferedImage
This method returns a buffered image with the contents of an image- Parameters:
image- the imageforce- If false then just return the image argument if its a BufferedImage- Returns:
- a buffered image
-
mergeImages
Merge images- Parameters:
images- list of imagesspace- space between imagesbg- background color- Returns:
- merged image
-
gridImages
Merge images- Parameters:
images- list of imagesspace- space between imagesbg- background colorcolumns- number of columns- Returns:
- merged image
-
gridImages2
Merge Images. The heuristic is not the same asgridImages(List, int, Color, int)so the results can be different.- Parameters:
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 grid- Returns:
- the image that has been gridded
-
padImage
Pad the image.- Parameters:
image- the imagespace- the spacecolor- the color- Returns:
- the image
-
mergeHorizontal
Merge the images horizontally.- Parameters:
images- the images- Returns:
- the image
-
mergeVertical
Merge the images vertically.- Parameters:
images- the images- Returns:
- the image
-
toBufferedImage
Create a BufferedImage from the given image- Parameters:
image- The imagetype- BufferedImage type- Returns:
- The BufferedImage
-
hasAlpha
Check to see if the image has alpha- Parameters:
image- the image- Returns:
- true if has alpha
-
getImage
Get the screen image from the component- Parameters:
component- The component.- Returns:
- Its image
- Throws:
Exception
-
writeImageToFile
Write a Buffered image to a file- Parameters:
image- image to writesaveFile- file to write to- Throws:
Exception- problem writing file
-
writeImageToFile
Write a Buffered image to a file- Parameters:
image- image to writesaveFile- file to write to- Throws:
Exception- problem writing file
-
horizontalflip
Flip the image horizontally From: Josiah Hester - http://www.javalobby.org/articles/ultimate-image- Parameters:
img- image- Returns:
- flipped image
-
verticalflip
Flip the image vertically From: Josiah Hester - http://www.javalobby.org/articles/ultimate-image- Parameters:
img- image- Returns:
- flipped image
-
rotate90
Rotate the image 90 degrees- Parameters:
img- imageleft- rotate counter clockwise- Returns:
- rotated image
-
convertImageTo
Convert an image to a new type- Parameters:
file- image filenewType- new image type- Returns:
- name of the new file
-
writeImageToFile
Write a Buffered image to a file at a particular quality- Parameters:
image- image to writesaveFile- file to write toquality- image quality (if supported)- Throws:
Exception- problem writing file
-
writeImageToFile
public static void writeImageToFile(Image image, String saveFile, OutputStream os, float quality) throws Exception Write a Buffered image to a file at a particular quality- Parameters:
image- image to writesaveFile- _more_os- output streamquality- image quality (if supported)- Throws:
Exception- problem writing file
-
isImage
Is the file name an image- Parameters:
file- file- Returns:
- is image
-
writeImage
Make a screen capture of the window. Write it to the file.- Parameters:
window- The windowfile- The file- Returns:
- Successful
- Throws:
Exception
-
writeImage
Make a screen capture of the window. Write it to the file.- Parameters:
window- The windowfile- The file- Returns:
- Successful
- Throws:
Exception
-
writeImageToFile
Take a screen snapshot of the component. Write it to the file.- Parameters:
component- The component.saveFile- The file.- Throws:
Exception
-
writeAvi
public static void writeAvi(List imageFiles, double frameRateInFPS, File outFile) throws IOException Write an AVI file- Parameters:
imageFiles- list of filesframeRateInFPS- frame rateoutFile- output file- Throws:
IOException- problem writing AVI
-
resize
Resize an image- Parameters:
image- the imagewidth- new widthheight- new height- Returns:
- resized image
-
getImage
Get an image from the component- Parameters:
editor- componenttransparentColor- if non null then set this color to be transparent- Returns:
- image
- Throws:
Exception- on badness
-
renderHtml
public static Image renderHtml(String html, int width, Color transparentColor, Font font) throws Exception Render the given html and return an image- Parameters:
html- html to renderwidth- image widthtransparentColor- if non null set this color in the image to be transparentfont- font to render with- Returns:
- image
- Throws:
Exception- on badness
-
getEditor
public static JEditorPane getEditor(String html, int width, Color transparentColor, Font font) throws Exception Make a editor pane from the html- Parameters:
html- htmlwidth- widthtransparentColor- what color to set as transparentfont- font- Returns:
- editor pane
- Throws:
Exception- on badness
-
getEditor
public static JEditorPane getEditor(JEditorPane editor, String html, int width, Color transparentColor, Font font) throws Exception Make a editor pane from the html- Parameters:
editor- Initial editorhtml- htmlwidth- widthtransparentColor- what color to set as transparentfont- font- Returns:
- editor pane
- Throws:
Exception- on badness
-
writePDF
test code- Parameters:
out- testcomp- test- Throws:
IOException- test
-
main
Read in the image. Wait util it is loaded in.- Parameters:
args- args- Throws:
Exception- problem with this
-
getImageFile
Read in the image from the given filename or url- Parameters:
file- File or url- Returns:
- The image
- Throws:
Exception- On badness
-
getColumnCountFromComps
Gets the column count from the components.- Parameters:
views- the views- Returns:
- the column from comp
-