Class ImageFX

    • Method Detail

      • isMultiResolutionImage

        public static boolean isMultiResolutionImage​(Image image)
      • averageColor

        public static Color averageColor​(BufferedImage image,
                                         int x0,
                                         int y0,
                                         int w,
                                         int h,
                                         int step)
        Compute an average color.
        Parameters:
        image - image
        x0 - start point of sub-image
        y0 - start point of sub-image
        w - width of sub-image
        h - height of sub-image
        step - sampling step
      • averageColor

        public static Color averageColor​(BufferedImage image,
                                         int step)
        Compute an average color.
        Parameters:
        image - image
        step - sampling step
      • toByteArray

        public static byte[] toByteArray​(Image image,
                                         String format)
                                  throws IOException
        Convert image to byte array using the specified format.
        Parameters:
        image - image
        format - format, e.g. "png"
        Returns:
        byte array
        Throws:
        IOException
      • toGray

        public static BufferedImage toGray​(Image image)
        Useful for creating grayed versions of images (e.g. disabled icons).
        Parameters:
        image - image
        Returns:
        grayed image
      • adjustToPanelBackground

        public static Color adjustToPanelBackground​(Color color)
      • adjustToUIBackground

        public static Color adjustToUIBackground​(Color color,
                                                 String uiKey)
      • isLight

        public static boolean isLight​(Color color)
      • lighten

        public static BufferedImage lighten​(Image image)
        Lightens an image, i.e. increases brightness. This can be used to create 'disabled' image buttons.
        Parameters:
        image - image
        Returns:
        brightened image
        See Also:
        ImageFX.LightenOp
      • createPictureFrame

        public static BufferedImage createPictureFrame​(Image image,
                                                       int width,
                                                       int height)
        Creates a new Image with the specified width and height and a rounded picture frame.
        Parameters:
        image - image
        width - width
        height - height
        Returns:
        framed image
      • createPictureFrame

        public static BufferedImage createPictureFrame​(Image image,
                                                       int width,
                                                       int height,
                                                       Paint paint,
                                                       Stroke stroke,
                                                       Map<?,​?> renderingHints)
        Creates a new Image with the specified width and height and a rounded picture frame.
        Parameters:
        image - image
        width - width
        height - height
        paint - paint for the picture frame
        stroke - stroke
        renderingHints - rendering hints @return framed image
      • addFrame

        public static BufferedImage addFrame​(Image image,
                                             int width,
                                             int height,
                                             Paint paint)
        Creates a new Image with the specified width and height and a rounded picture frame.
        Parameters:
        image - image
        width - width
        height - height
        Returns:
        framed image
      • addShape

        public static BufferedImage addShape​(Image image,
                                             int width,
                                             int height,
                                             Paint paint,
                                             Shape shape)
        Creates a new Image with the specified width and height and the specified shape.
        Parameters:
        image - image
        width - width
        height - height
        shape - shape
        Returns:
        framed image
      • addDropShadow

        public static BufferedImage addDropShadow​(Image image,
                                                  int width,
                                                  int height)
      • addDropShadow

        public static BufferedImage addDropShadow​(Image image,
                                                  int width,
                                                  int height,
                                                  float angle,
                                                  int distance,
                                                  int shadowSize,
                                                  float opacity,
                                                  Color color)
      • toBufferedImage

        public static BufferedImage toBufferedImage​(Icon icon,
                                                    float scaleFactor)
      • toScreenCompatibleImageIcon

        public static ImageIcon toScreenCompatibleImageIcon​(ImageIcon imageIcon)
        Make sure the icons are screen compatible to make drawing them faster.
        Parameters:
        imageIcon - an imageicon to transform
        Returns:
        image icon the screen compatible image icon
      • toScreenCompatibleImage

        public static BufferedImage toScreenCompatibleImage​(Image image)
        Make sure the image is screen compatible to make drawing them faster.
        Parameters:
        image - an image to transform
        Returns:
        image the screen compatible image
      • toARGBImageIcon

        public static ImageIcon toARGBImageIcon​(ImageIcon imageIcon)
        Make sure the icons are screen compatible to make drawing them faster.
        Parameters:
        imageIcon - an imageicon to transform
        Returns:
        image icon the screen compatible image icon
      • toARGBImage

        public static BufferedImage toARGBImage​(Image image)
        Converts an image that is either pre-multiplied or does not even have an alpha channel to ARGB.
        Parameters:
        image - image
        Returns:
        ARGB image
      • getHiDPIScaleFactor

        public static float getHiDPIScaleFactor()
        Return the system's content (HiDPI, aka Retina) scale factor. On macOS this corresponds to the Toolkit.getDesktopProperty(String) apple.awt.contentScaleFactor.
        Returns:
        usually 1.0f for regular content and 2.0f for HiDPI/Retina content.
      • getScaleFactor

        public static int getScaleFactor()
        Scale factor that components should be made bigger to appear normal on Windows HiDPI displays. This is needed because current Java 8 (as of u72) behaves differently than macOS. It uses screen, not virtual coordinates.
        Returns:
        scale factor
      • getHiDPIScaleFactor

        public static float getHiDPIScaleFactor​(Graphics g)
        Returns the graphics' object scale factor.
        Parameters:
        g - graphics object
        Returns:
        scale factor
      • useHiDPIScaling

        public static boolean useHiDPIScaling()
        Indicates whether we need to take HiDPI scaling into account.
        Returns:
        true of getHiDPIScaleFactor() != 1f
      • createARGBScratchBuffer

        public static BufferedImage createARGBScratchBuffer​(int width,
                                                            int height)
      • createIntARGBScratchBuffer

        public static BufferedImage createIntARGBScratchBuffer​(int width,
                                                               int height)
      • createCompatibleImage

        public static BufferedImage createCompatibleImage​(int width,
                                                          int height,
                                                          float scaleFactor)
        Creates a translucent BufferedImage of the specified size, modified by the given scale factor.
        Parameters:
        width - width
        height - height
        scaleFactor - scale factor
        Returns:
        buffered image compatible for the default device with width and height of pixel x scaleFactor
      • createCompatibleImage

        public static BufferedImage createCompatibleImage​(Component component,
                                                          int width,
                                                          int height,
                                                          int transparency,
                                                          float scaleFactor)
      • getDefaultScreenDevice

        public static GraphicsDevice getDefaultScreenDevice()
        Because of JDK-8152683, which causes a rare hang when calling GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(), we are only calling this method from the EDT. It is our hope that this may fix the issue. If not, it will at least let us monitor the calls.
        Returns:
        default screen device
      • createCompatibleImage

        public static BufferedImage createCompatibleImage​(int width,
                                                          int height)
        Creates a screen compatible image.
        Parameters:
        width - width
        height - height
        Returns:
        image screen compatible image
      • addReflection

        public static BufferedImage addReflection​(Image image,
                                                  int width)
        Creates a new image from the source image that has a width of side and a height of 1.5 x side (no matter what). The lower third of the resulting image is a reflection of the upper two thirds. If the source image is not square, the resulting image has appropriate margins. I.e. if the source image is wider than high, at the top and the bottom of the scaled and reflected image you'll find some empty space.

        The resulting image is a HiDPI image, if possible.

        Parameters:
        image - source image
        width - width, 1.5 x height
        Returns:
        image
      • addReflection

        public static void addReflection​(Image sourceImage,
                                         BufferedImage imageWithReflection)
        Paints the given image to a destination image and adds a reflection below.
        Parameters:
        sourceImage - source image
        imageWithReflection - image to paint the result to
      • createReflection

        public static Image createReflection​(int width,
                                             int height,
                                             Image image)
        Creates a reflection of an image (without the image itself).
        Parameters:
        width - width
        height - height
        image - source image
        Returns:
        result image
      • createDisabledIcon

        public static Icon createDisabledIcon​(Icon icon)
        Creates a disabled (light, gray) version of the given icon, taking HiDPI issues into account.
        Parameters:
        icon - icon
        Returns:
        disabled icon
        See Also:
        toGray(java.awt.Image), lighten(java.awt.Image)
      • createGrayIcon

        public static Icon createGrayIcon​(Icon icon)
        Creates a gray version of the given icon.
        Parameters:
        icon - icon
        Returns:
        gray version
      • createNegativeIcon

        public static Icon createNegativeIcon​(Icon icon)
        Creates a negative version of the given icon.
        Parameters:
        icon - icon
        Returns:
        negative version