Class ImageUtils


  • public class ImageUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.awt.Color TRANSPARENT  
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.image.BufferedImage addBorder​(java.awt.image.BufferedImage image, java.awt.Color borderColor, int borderWidth, int cornerRadius)  
      static java.awt.image.BufferedImage base64Decode​(java.io.File file)  
      static java.awt.image.BufferedImage base64Decode​(java.lang.String encoded)  
      static java.lang.String base64Encode​(java.awt.image.BufferedImage image)  
      static java.lang.String base64Encode​(java.io.File file)  
      static java.awt.image.BufferedImage cropImage​(java.awt.image.BufferedImage image, int trimLeft, int trimRight, int trimTop, int trimBottom)  
      static java.awt.image.BufferedImage drawHighlightOval​(java.awt.image.BufferedImage image, int x, int y, int w, int h, java.awt.Color borderColor, int borderWidth, java.awt.Color innerFillColor)  
      static java.awt.image.BufferedImage drawHighlightRectangle​(java.awt.image.BufferedImage image, int x, int y, int w, int h, java.awt.Color borderColor, int borderWidth, int cornerRadius, java.awt.Color innerFillColor)  
      static java.awt.image.BufferedImage drawOval​(java.awt.image.BufferedImage image, int x, int y, int w, int h, java.awt.Color borderColor, int borderWidth, float[] dash, float dashPhase)  
      static java.awt.image.BufferedImage drawRectangle​(java.awt.image.BufferedImage image, int x, int y, int w, int h, java.awt.Color borderColor, int borderWidth, int cornerRadius)  
      static java.awt.image.BufferedImage drawRectangle​(java.awt.image.BufferedImage image, int x, int y, int w, int h, java.awt.Color borderColor, int borderWidth, int cornerRadius, float[] dash, float dashPhase)  
      static byte[] getImageBytes​(java.awt.image.BufferedImage image)  
      static java.awt.Image getImageFromClipboard()  
      static java.awt.Image getImageFromTransferable​(java.awt.datatransfer.Transferable transferable)  
      static boolean isEncodedImage​(java.lang.String encoded)  
      static boolean isPossiblyEncodedImage​(java.lang.String encoded)  
      static java.awt.image.BufferedImage loadImageFromContent​(byte[] cachedImageBytes, java.lang.String idPath)  
      static java.awt.image.BufferedImage loadImageFromFile​(java.io.File cachedImageFile)  
      static java.awt.image.BufferedImage loadImageFromURL​(java.lang.String imageURL)  
      static java.awt.image.BufferedImage loadImageFromURL​(java.lang.String imageURL, boolean logImageProcessing)
      Load image from URL.
      static java.awt.image.BufferedImage makeRoundedCorner​(java.awt.image.BufferedImage image, int cornerRadius, int borderWidth)  
      static java.awt.image.BufferedImage punchOuterHighlightOval​(java.awt.image.BufferedImage image, java.awt.image.BufferedImage outerImage, int x, int y, int w, int h, int borderWidth, java.awt.Color outerFillColor, int outerBorderWidth, int outerCornerRadius, boolean applyToImage)  
      static java.awt.image.BufferedImage punchOuterHighlightRectangle​(java.awt.image.BufferedImage image, java.awt.image.BufferedImage outerImage, int x, int y, int w, int h, int borderWidth, int cornerRadius, java.awt.Color outerFillColor, int outerBorderWidth, int outerCornerRadius, boolean applyToImage)  
      static java.awt.image.BufferedImage removeAlpha​(java.awt.image.BufferedImage image)  
      static void save​(java.awt.image.BufferedImage image, java.io.File file, java.lang.String format)  
      static java.awt.image.BufferedImage scaleImage​(java.awt.image.BufferedImage sourceImage, int newWidth, int newHeight, int opType)  
      static java.awt.image.BufferedImage toBufferedImage​(java.awt.Image src)  
      static java.awt.Image toTransparent​(java.awt.image.BufferedImage image, java.awt.Color color, int tolerance)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TRANSPARENT

        public static java.awt.Color TRANSPARENT
    • Constructor Detail

      • ImageUtils

        public ImageUtils()
    • Method Detail

      • getImageFromClipboard

        public static java.awt.Image getImageFromClipboard()
      • getImageFromTransferable

        public static java.awt.Image getImageFromTransferable​(java.awt.datatransfer.Transferable transferable)
      • scaleImage

        public static java.awt.image.BufferedImage scaleImage​(java.awt.image.BufferedImage sourceImage,
                                                              int newWidth,
                                                              int newHeight,
                                                              int opType)
      • toBufferedImage

        public static java.awt.image.BufferedImage toBufferedImage​(java.awt.Image src)
      • save

        public static void save​(java.awt.image.BufferedImage image,
                                java.io.File file,
                                java.lang.String format)
      • loadImageFromFile

        public static java.awt.image.BufferedImage loadImageFromFile​(java.io.File cachedImageFile)
        Parameters:
        cachedImageFile - file
        Returns:
        Could be null if the image could not be read from the file (because of whatever strange reason).
      • loadImageFromContent

        public static java.awt.image.BufferedImage loadImageFromContent​(byte[] cachedImageBytes,
                                                                        java.lang.String idPath)
        Parameters:
        cachedImageBytes - file
        idPath - image file path for error reporting
        Returns:
        Could be null if the image could not be read from the file (because of whatever strange reason).
      • base64Encode

        public static java.lang.String base64Encode​(java.awt.image.BufferedImage image)
      • base64Encode

        public static java.lang.String base64Encode​(java.io.File file)
      • base64Decode

        public static java.awt.image.BufferedImage base64Decode​(java.io.File file)
      • isEncodedImage

        public static boolean isEncodedImage​(java.lang.String encoded)
      • isPossiblyEncodedImage

        public static boolean isPossiblyEncodedImage​(java.lang.String encoded)
      • base64Decode

        public static java.awt.image.BufferedImage base64Decode​(java.lang.String encoded)
      • loadImageFromURL

        public static java.awt.image.BufferedImage loadImageFromURL​(java.lang.String imageURL)
      • loadImageFromURL

        public static java.awt.image.BufferedImage loadImageFromURL​(java.lang.String imageURL,
                                                                    boolean logImageProcessing)
        Load image from URL.

        NOTE: Java7 JDK cannot load some images including GitHub emoji. Compiling this library with Java8 solves the problem.

        Parameters:
        imageURL - url of the image
        logImageProcessing - true if errors are to print to console
        Returns:
        image or null if failed to download.
      • makeRoundedCorner

        public static java.awt.image.BufferedImage makeRoundedCorner​(java.awt.image.BufferedImage image,
                                                                     int cornerRadius,
                                                                     int borderWidth)
      • addBorder

        public static java.awt.image.BufferedImage addBorder​(java.awt.image.BufferedImage image,
                                                             java.awt.Color borderColor,
                                                             int borderWidth,
                                                             int cornerRadius)
      • drawRectangle

        public static java.awt.image.BufferedImage drawRectangle​(java.awt.image.BufferedImage image,
                                                                 int x,
                                                                 int y,
                                                                 int w,
                                                                 int h,
                                                                 java.awt.Color borderColor,
                                                                 int borderWidth,
                                                                 int cornerRadius)
      • drawRectangle

        public static java.awt.image.BufferedImage drawRectangle​(java.awt.image.BufferedImage image,
                                                                 int x,
                                                                 int y,
                                                                 int w,
                                                                 int h,
                                                                 java.awt.Color borderColor,
                                                                 int borderWidth,
                                                                 int cornerRadius,
                                                                 float[] dash,
                                                                 float dashPhase)
      • drawOval

        public static java.awt.image.BufferedImage drawOval​(java.awt.image.BufferedImage image,
                                                            int x,
                                                            int y,
                                                            int w,
                                                            int h,
                                                            java.awt.Color borderColor,
                                                            int borderWidth,
                                                            float[] dash,
                                                            float dashPhase)
      • drawHighlightRectangle

        public static java.awt.image.BufferedImage drawHighlightRectangle​(java.awt.image.BufferedImage image,
                                                                          int x,
                                                                          int y,
                                                                          int w,
                                                                          int h,
                                                                          java.awt.Color borderColor,
                                                                          int borderWidth,
                                                                          int cornerRadius,
                                                                          java.awt.Color innerFillColor)
      • drawHighlightOval

        public static java.awt.image.BufferedImage drawHighlightOval​(java.awt.image.BufferedImage image,
                                                                     int x,
                                                                     int y,
                                                                     int w,
                                                                     int h,
                                                                     java.awt.Color borderColor,
                                                                     int borderWidth,
                                                                     java.awt.Color innerFillColor)
      • punchOuterHighlightRectangle

        public static java.awt.image.BufferedImage punchOuterHighlightRectangle​(java.awt.image.BufferedImage image,
                                                                                java.awt.image.BufferedImage outerImage,
                                                                                int x,
                                                                                int y,
                                                                                int w,
                                                                                int h,
                                                                                int borderWidth,
                                                                                int cornerRadius,
                                                                                java.awt.Color outerFillColor,
                                                                                int outerBorderWidth,
                                                                                int outerCornerRadius,
                                                                                boolean applyToImage)
      • punchOuterHighlightOval

        public static java.awt.image.BufferedImage punchOuterHighlightOval​(java.awt.image.BufferedImage image,
                                                                           java.awt.image.BufferedImage outerImage,
                                                                           int x,
                                                                           int y,
                                                                           int w,
                                                                           int h,
                                                                           int borderWidth,
                                                                           java.awt.Color outerFillColor,
                                                                           int outerBorderWidth,
                                                                           int outerCornerRadius,
                                                                           boolean applyToImage)
      • cropImage

        public static java.awt.image.BufferedImage cropImage​(java.awt.image.BufferedImage image,
                                                             int trimLeft,
                                                             int trimRight,
                                                             int trimTop,
                                                             int trimBottom)
      • removeAlpha

        public static java.awt.image.BufferedImage removeAlpha​(java.awt.image.BufferedImage image)
      • toTransparent

        public static java.awt.Image toTransparent​(java.awt.image.BufferedImage image,
                                                   java.awt.Color color,
                                                   int tolerance)
      • getImageBytes

        public static byte[] getImageBytes​(java.awt.image.BufferedImage image)