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 BufferedImage
clip
(BufferedImage image, int[] ul, int[] lr) Clip the imagestatic String
convertImageTo
(String file, String newType) Convert an image to a new typestatic int
getColumnCountFromComps
(List<? extends Component> views) Gets the column count from the components.static JEditorPane
Make a editor pane from the htmlstatic JEditorPane
getEditor
(JEditorPane editor, String html, int width, Color transparentColor, Font font) Make a editor pane from the htmlstatic Image
Get the screen image from the componentstatic Image
getImage
(JEditorPane editor, Color transparentColor) Get an image from the componentstatic Image
getImageFile
(String file) Read in the image from the given filename or urlstatic Image
gridImages
(List images, int space, Color bg, int columns) Merge imagesstatic Image
gridImages2
(List<? extends Image> images, int space, Color bg, int columns) Merge Images.static boolean
Check to see if the image has alphastatic BufferedImage
Flip the image horizontally From: Josiah Hester - http://www.javalobby.org/articles/ultimate-imagestatic boolean
Is the file name an imagestatic void
Read in the image.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.static BufferedImage
makeColorTransparent
(Image im, Color c) Make a color in the image transparentstatic BufferedImage
matte
(BufferedImage image, int top, int bottom, int left, int right, Color bg) Add a matte border around the imagestatic Image
mergeHorizontal
(List<? extends Image> images) Merge the images horizontally.static Image
mergeImages
(List images, int space, Color bg) Merge imagesstatic Image
mergeVertical
(List<? extends Image> images) Merge the images vertically.static Image
Pad the image.static Point
parsePoint
(String s, Rectangle r) Parse the string specification of a point with respect to the rectangle.static Image
Read and imagestatic Image
Read and imagestatic Image
Read and imagestatic BufferedImage
removeRedeye
(Image im, int x1, int y1, int x2, int y2) Remove the brighter red from the imagestatic Image
renderHtml
(String html, int width, Color transparentColor, Font font) Render the given html and return an imagestatic Image
Resize an imagestatic BufferedImage
rotate90
(BufferedImage img, boolean left) Rotate the image 90 degreesstatic BufferedImage
Set the alpha channel to the given transparency percentstatic int
toAlpha
(double percent) Change the transparency percentage into an int alpha valuestatic BufferedImage
toBufferedImage
(Image image) This method returns a buffered image with the contents of an imagestatic BufferedImage
toBufferedImage
(Image image, boolean force) This method returns a buffered image with the contents of an imagestatic BufferedImage
toBufferedImage
(Image image, int type) Create a BufferedImage from the given imagestatic Point
convenience to convert to a Pointstatic BufferedImage
Flip the image vertically From: Josiah Hester - http://www.javalobby.org/articles/ultimate-imagestatic Image
waitOnImage
(Image image) Wait until it is loaded in.static void
Write an AVI filestatic boolean
writeImage
(JDialog window, String file) Make a screen capture of the window.static boolean
writeImage
(JFrame window, String file) Make a screen capture of the window.static void
writeImageToFile
(Component component, String saveFile) Take a screen snapshot of the component.static void
writeImageToFile
(Image image, File saveFile) Write a Buffered image to a filestatic void
writeImageToFile
(Image image, String saveFile) Write a Buffered image to a filestatic void
writeImageToFile
(Image image, String saveFile, float quality) Write a Buffered image to a file at a particular qualitystatic void
writeImageToFile
(Image image, String saveFile, OutputStream os, float quality) Write a Buffered image to a file at a particular qualitystatic void
writePDF
(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
-