Class ImageUtils

java.lang.Object
com.everdro1d.libs.swing.ImageUtils

public class ImageUtils extends Object
Utility class for handling image-related operations in Swing applications.

This class provides methods for setting frame icons, retrieving application icons, changing icon colors, and applying transformations such as darkening icons.

Features:

  • Set the icon of a JFrame from application resources.
  • Retrieve an image as an Icon from the application's resources.
  • Change the color of an icon while preserving transparency.
  • Darken an icon by reducing its brightness.

Example Usage:

 JFrame frame = new JFrame();
 ImageUtils.setFrameIcon(frame, "icons/app_icon.png", MyApp.class);
 

Note: This class cannot be instantiated.

  • Method Details

    • setFrameIcon

      public static void setFrameIcon(JFrame frame, String internalPath, Class<?> clazz)
      Set the icon of the frame.
      Parameters:
      frame - the frame to set the icon of
      internalPath - path to the image file within resources
      clazz - the class to trace from
    • getApplicationIcon

      public static Icon getApplicationIcon(String internalPath, Class<?> clazz)
      Retrieve an image as an Icon from the application's resources.
      Parameters:
      internalPath - path to the image file within resources
      clazz - the class to trace from
      Returns:
      the Icon
    • changeIconColor

      public static ImageIcon changeIconColor(Icon icon, Color color)
      Changes the color of a given icon to the specified color.

      This method creates a new image from the provided icon and applies a color filter to replace the RGB values of non-transparent pixels with the specified color while preserving the alpha (transparency) values.

      Parameters:
      icon - the icon to change the color of
      color - the new color to apply to the icon
      Returns:
      a new ImageIcon with the applied color, or null if an error occurs
    • darkenIcon

      public static ImageIcon darkenIcon(Icon icon)
      Darkens the given icon by reducing the brightness of its colors.

      This method creates a new image from the provided icon and applies a darker color transformation to each pixel while preserving the alpha (transparency) values.

      Parameters:
      icon - the icon to darken
      Returns:
      a new ImageIcon with the darkened colors, or null if an error occurs