Class ImageUtils


  • public class ImageUtils
    extends Object
    • Field Detail

      • TRANSPARENT

        public static Color TRANSPARENT
    • Constructor Detail

      • ImageUtils

        public ImageUtils()
    • Method Detail

      • getImageFromClipboard

        public static Image getImageFromClipboard()
      • getImageFromTransferable

        public static Image getImageFromTransferable​(Transferable transferable)
      • loadImageFromFile

        public static BufferedImage loadImageFromFile​(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 BufferedImage loadImageFromContent​(byte[] cachedImageBytes,
                                                         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 String base64Encode​(File file)
      • isEncodedImage

        public static boolean isEncodedImage​(String encoded)
      • isPossiblyEncodedImage

        public static boolean isPossiblyEncodedImage​(String encoded)
      • loadImageFromURL

        public static BufferedImage loadImageFromURL​(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.
      • drawRectangle

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

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

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

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

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

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

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

        public static BufferedImage cropImage​(BufferedImage image,
                                              int trimLeft,
                                              int trimRight,
                                              int trimTop,
                                              int trimBottom)
      • getImageBytes

        public static byte[] getImageBytes​(BufferedImage image)