Class ImageUtils

java.lang.Object
net.mcreator.util.image.ImageUtils

public class ImageUtils extends Object
  • Constructor Details

    • ImageUtils

      public ImageUtils()
  • Method Details

    • drawOver

      public static ImageIcon drawOver(ImageIcon i, ImageIcon wh)
    • drawOver

      public static ImageIcon drawOver(ImageIcon i, ImageIcon wh, int xp, int yp, int w, int h)
    • createColorSquare

      public static ImageIcon createColorSquare(Color color, int width, int height)
    • colorize

      public static ImageIcon colorize(ImageIcon icon, Color modifier, boolean type)
    • changeSaturation

      public static ImageIcon changeSaturation(ImageIcon icon, float modifier)
    • resize

      public static Image resize(Image image, int size)
    • resizeAA

      public static Image resizeAA(Image image, int size)
    • resize

      public static Image resize(Image image, int w, int h)
    • resizeAA

      public static Image resizeAA(Image image, int w, int h)
    • resizeAndCrop

      public static BufferedImage resizeAndCrop(Image image, int size)
    • emptyImageWithSize

      public static BufferedImage emptyImageWithSize(int size, int y, Color color)
    • eraseRect

      public static BufferedImage eraseRect(Image image, int x, int y, int w, int h)
    • eraseExceptRect

      public static BufferedImage eraseExceptRect(Image image, int x, int y, int w, int h)
    • maskTransparency

      public static BufferedImage maskTransparency(BufferedImage base, BufferedImage mask)
    • toBufferedImage

      public static BufferedImage toBufferedImage(Image img)
      Converts a given Image into a BufferedImage
      Parameters:
      img - The Image to be converted
      Returns:
      The converted BufferedImage
    • translate

      public static BufferedImage translate(Image img, double x, double y)
    • rotate

      public static BufferedImage rotate(Image img, int degrees)
    • rotate

      public static ImageIcon rotate(ImageIcon ic, int degrees)
    • crop

      public static BufferedImage crop(BufferedImage src, Rectangle rect)
    • cover

      public static Image cover(Image image, Dimension dimension)
    • darken

      public static BufferedImage darken(BufferedImage image)
    • brighten

      public static BufferedImage brighten(BufferedImage image)
    • deepCopy

      public static BufferedImage deepCopy(BufferedImage bi)
    • noiseHSV

      public static BufferedImage noiseHSV(BufferedImage image, float hfactor, float sfactor, float vfactor, long seed)
    • fit

      public static ImageIcon fit(Image image, int size)
    • fit

      public static ImageIcon fit(Image image, int width, int height)
    • autoCropTile

      public static BufferedImage autoCropTile(BufferedImage tile)
    • randomTile

      public static Image randomTile(BufferedImage tile, Random random)
    • generateCuboidImage

      public static BufferedImage generateCuboidImage(Image texture, int x, int y, int z, int xOff, int yOff, int zOff)
    • generateCuboidImage

      public static BufferedImage generateCuboidImage(Image top, Image front, Image side, int x, int y, int z, int xOff, int yOff, int zOff)
      Generates a cuboid image given the textures, the dimensions, and the offsets on the axes.
      Parameters:
      top -

      The top face texture

      front -

      The front face texture

      side -

      The side (right) face texture

      x -

      The length of the cuboid (width of the side face)

      y -

      The height of the cuboid

      z -

      The width of the cuboid (width of the front face)

      xOff -

      The horizontal offset of the cuboid, towards the front face

      yOff -

      The vertical offset of the cuboid, towards the top face

      zOff -

      The horizontal of the cuboid, towards the side face

      Returns:

      Returns generated image.

    • getAverageColor

      public static Color getAverageColor(BufferedImage image)
    • getAverageLuminance

      public static float getAverageLuminance(BufferedImage image)
    • mergeTwoImages

      public static BufferedImage mergeTwoImages(Image first, Image second, int width, int height, int xFirst, int yFirst, int xSecond, int ySecond)
      Merges two images to make a single image
      Parameters:
      first -

      The first image to draw on the new image

      second -

      The second image to draw on the new image

      width -

      The width of the final image

      height -

      The height of the final image

      xFirst -

      The x position of the first image on the final image

      yFirst -

      The y position of the first image on the final image

      xSecond -

      The x position of the second image on the final image

      ySecond -

      The y position of the second image on the final image

      Returns:

      Returns the generated image.

    • checkIfSameWidth

      public static boolean checkIfSameWidth(Image first, Image second)
    • checkIfSameHeight

      public static boolean checkIfSameHeight(Image first, Image second)
    • checkIfSameSize

      public static boolean checkIfSameSize(Image first, Image second)
      Checks if two images have the same width and the same height
      Parameters:
      first -

      The first image

      second -

      The second image

      Returns:

      Returns true if the provided images have the same width and the same height

    • generateSquircle

      public static Image generateSquircle(Color color, int fac, int radius, int width, int height, ImageObserver observer)
      Generates a smooth squircle shape
      Parameters:
      color -

      Color of the generated smooth squircle

      fac -

      Upscale factor (generates a bigger image before downscaling to get better visual results)

      radius -

      The squircle corner radius

      width -

      Squircle width

      height -

      Squircle height

      observer -

      Observer used when drawing the image (can be the current swing component)

      Returns:

      The generated image

    • cropSquircle

      public static Image cropSquircle(Image original, int fac, int radius, int width, int height, ImageObserver observer)
      Crops the input image in a squircle shape
      Parameters:
      original -

      The original image

      fac -

      Upscale factor (upscales the image before cropping to produce smooth edges after downscaling to the desired size)

      radius -

      The squircle corner radius

      width -

      Squircle width

      height -

      Squircle height

      observer -

      Observer used when drawing the image (can be the current swing component)

      Returns:

      The cropped image

    • generateShadow

      public static Image generateShadow(int radius, int shadowRadius, int shadowExtension, int width, int height)
      Generates a shadow that fits squircle cropped images.
      Parameters:
      radius -

      The squircle corner radius

      shadowRadius -

      Width of the blur shadow

      shadowExtension -

      The squircle extension

      width -

      Squircle width

      height -

      Squircle height

      Returns:

      Returns the generated shadow.

    • generateGaussianKernel

      public static float[] generateGaussianKernel(int radius)
      Generates a gaussian kernel compatible with java.awt.image.Kernel objects.
      Parameters:
      radius -

      The gaussian kernel radius

      Returns:

      The generated kernel