Class Imaging

java.lang.Object
de.gurkenlabs.litiengine.util.Imaging

public final class Imaging
extends java.lang.Object
  • Field Summary

    Fields 
    Modifier and TypeFieldDescription
    static intCROP_ALIGN_CENTER 
    static intCROP_ALIGN_LEFT 
    static intCROP_ALIGN_RIGHT 
    static intCROP_VALIGN_BOTTOM 
    static intCROP_VALIGN_CENTER 
    static intCROP_VALIGN_TOP 
    static intCROP_VALIGN_TOPCENTER 
  • Method Summary

    Modifier and TypeMethodDescription
    static java.awt.image.BufferedImageaddShadow​(java.awt.image.BufferedImage image, int xOffset, int yOffset)
    Adds a shadow effect by executing the following steps: 1.
    static java.awt.image.BufferedImageapplyAlphaChannel​(java.awt.image.BufferedImage img, java.awt.Color color)
    All pixels that have the specified color are rendered transparent.
    static booleanareEqual​(java.awt.image.BufferedImage image1, java.awt.image.BufferedImage image2) 
    static java.awt.image.BufferedImageborderAlpha​(java.awt.image.BufferedImage image, java.awt.Color strokeColor, boolean borderOnly) 
    static java.awt.image.BufferedImagecopy​(java.awt.image.BufferedImage image)
    Creates a new BufferedImage instance from the specified image.
    static java.awt.image.BufferedImagecrop​(java.awt.image.BufferedImage image, int cropAlignment, int cropVerticlaAlignment, int width, int height)
    Crops a sub image from the specified image.
    static java.awt.image.BufferedImageflashVisiblePixels​(java.awt.Image image, java.awt.Color flashColor)
    All pixels that are not transparent are replaced by a pixel of the specified flashColor.
    static java.awt.image.BufferedImageflipSpritesHorizontally​(Spritesheet sprite) 
    static java.awt.image.BufferedImageflipSpritesVertically​(Spritesheet sprite) 
    static java.awt.image.BufferedImagegetCompatibleImage​(int width, int height) 
    static java.awt.image.BufferedImage[][]getSubImages​(java.awt.image.BufferedImage image, int rows, int columns)
    Gets a two dimensional grid that contains parts of the specified image.
    static java.awt.image.BufferedImagehorizontalFlip​(java.awt.image.BufferedImage img)
    Flips the specified image horizontally.
    static booleanisEmpty​(java.awt.image.BufferedImage image) 
    static java.awt.image.BufferedImagereplaceColors​(java.awt.image.BufferedImage bufferedImage, java.util.Map<java.awt.Color,​java.awt.Color> colorMappings)
    Replace colors in an image according to a Map containing source colors and target colors, then return the result.
    static java.awt.image.BufferedImagerotate​(java.awt.image.BufferedImage bufferedImage, double radians) 
    static java.awt.image.BufferedImagerotate​(java.awt.image.BufferedImage bufferedImage, Rotation rotation) 
    static java.awt.image.BufferedImagescale​(java.awt.image.BufferedImage image, double factor) 
    static java.awt.image.BufferedImagescale​(java.awt.image.BufferedImage image, double factor, boolean keepRatio) 
    static java.awt.image.BufferedImagescale​(java.awt.image.BufferedImage image, int max) 
    static java.awt.image.BufferedImagescale​(java.awt.image.BufferedImage image, int width, int height)
    The specified image is scaled to a new dimension with the specified width and height.
    static java.awt.image.BufferedImagescale​(java.awt.image.BufferedImage image, int width, int height, boolean keepRatio) 
    static java.awt.image.BufferedImagescale​(java.awt.image.BufferedImage image, int width, int height, boolean keepRatio, boolean fill) 
    static java.awt.image.BufferedImagesetOpacity​(java.awt.Image img, float opacity) 
    static java.awt.image.BufferedImagetoBufferedImage​(java.awt.Image img) 
    static java.awt.image.BufferedImagetoCompatibleImage​(java.awt.image.BufferedImage image) 
    static java.awt.image.BufferedImageverticalFlip​(java.awt.image.BufferedImage img)
    Flips the specified image vertically.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • addShadow

      public static java.awt.image.BufferedImage addShadow​(java.awt.image.BufferedImage image, int xOffset, int yOffset)
      Adds a shadow effect by executing the following steps: 1. Transform visible pixels to a semi-transparent black 2. Flip the image vertically 3. Scale it down 4. Render original image and shadow on a buffered image

      TODO: Add support for different shadow types. Add an ellipse shadow, etc..

      Parameters:
      image - the image
      xOffset - the x offset
      yOffset - the y offset
      Returns:
      the buffered image
    • applyAlphaChannel

      public static java.awt.image.BufferedImage applyAlphaChannel​(java.awt.image.BufferedImage img, java.awt.Color color)
      All pixels that have the specified color are rendered transparent.
      Parameters:
      img - the img
      color - the color
      Returns:
      the image
    • borderAlpha

      public static java.awt.image.BufferedImage borderAlpha​(java.awt.image.BufferedImage image, java.awt.Color strokeColor, boolean borderOnly)
    • isEmpty

      public static boolean isEmpty​(java.awt.image.BufferedImage image)
    • areEqual

      public static boolean areEqual​(java.awt.image.BufferedImage image1, java.awt.image.BufferedImage image2)
    • crop

      public static java.awt.image.BufferedImage crop​(java.awt.image.BufferedImage image, int cropAlignment, int cropVerticlaAlignment, int width, int height)
      Crops a sub image from the specified image.
      Parameters:
      image - The image to crop the sub-image from.
      cropAlignment - use the following consts:
      cropVerticlaAlignment - use the following consts:
      width - The width to crop.
      height - The height to crop.
      Returns:
      The cropped image or the original image if it is smaller than the specified dimensions.
    • flashVisiblePixels

      public static java.awt.image.BufferedImage flashVisiblePixels​(java.awt.Image image, java.awt.Color flashColor)
      All pixels that are not transparent are replaced by a pixel of the specified flashColor.
      Parameters:
      image - the image
      flashColor - the flash color
      Returns:
      the buffered image
    • flipSpritesHorizontally

      public static java.awt.image.BufferedImage flipSpritesHorizontally​(Spritesheet sprite)
    • flipSpritesVertically

      public static java.awt.image.BufferedImage flipSpritesVertically​(Spritesheet sprite)
    • copy

      public static java.awt.image.BufferedImage copy​(java.awt.image.BufferedImage image)
      Creates a new BufferedImage instance from the specified image.
      Parameters:
      image - The image to be copied.
      Returns:
      A copy of the specified image.
    • getCompatibleImage

      public static java.awt.image.BufferedImage getCompatibleImage​(int width, int height)
    • getSubImages

      public static java.awt.image.BufferedImage[][] getSubImages​(java.awt.image.BufferedImage image, int rows, int columns)
      Gets a two dimensional grid that contains parts of the specified image. Splits up the specified image into a grid with the defined number of rows and columns.
      Parameters:
      image - The base image that will be split up.
      rows - The number of rows.
      columns - The number or columns.
      Returns:
      A two dimensional array with all the sub-images.
    • horizontalFlip

      public static java.awt.image.BufferedImage horizontalFlip​(java.awt.image.BufferedImage img)
      Flips the specified image horizontally.
      Parameters:
      img - The image to be flipped.
      Returns:
      The flipped image.
    • verticalFlip

      public static java.awt.image.BufferedImage verticalFlip​(java.awt.image.BufferedImage img)
      Flips the specified image vertically.
      Parameters:
      img - The image to be flipped.
      Returns:
      The flipped image.
    • replaceColors

      public static java.awt.image.BufferedImage replaceColors​(java.awt.image.BufferedImage bufferedImage, java.util.Map<java.awt.Color,​java.awt.Color> colorMappings)
      Replace colors in an image according to a Map containing source colors and target colors, then return the result.
      Parameters:
      bufferedImage - the original image
      colorMappings - a Map with source colors as keys and target colors as values
      Returns:
      a new version of the original image, where the source colors are replaced with the target colors.
    • rotate

      public static java.awt.image.BufferedImage rotate​(java.awt.image.BufferedImage bufferedImage, Rotation rotation)
    • rotate

      public static java.awt.image.BufferedImage rotate​(java.awt.image.BufferedImage bufferedImage, double radians)
    • scale

      public static java.awt.image.BufferedImage scale​(java.awt.image.BufferedImage image, int max)
    • scale

      public static java.awt.image.BufferedImage scale​(java.awt.image.BufferedImage image, double factor)
    • scale

      public static java.awt.image.BufferedImage scale​(java.awt.image.BufferedImage image, double factor, boolean keepRatio)
    • scale

      public static java.awt.image.BufferedImage scale​(java.awt.image.BufferedImage image, int width, int height)
      The specified image is scaled to a new dimension with the specified width and height. This method doesn't use anti aliasing for this process to keep the indy look.
      Parameters:
      image - the image
      width - the width
      height - the height
      Returns:
      the buffered image
    • scale

      public static java.awt.image.BufferedImage scale​(java.awt.image.BufferedImage image, int width, int height, boolean keepRatio)
    • scale

      public static java.awt.image.BufferedImage scale​(java.awt.image.BufferedImage image, int width, int height, boolean keepRatio, boolean fill)
    • setOpacity

      public static java.awt.image.BufferedImage setOpacity​(java.awt.Image img, float opacity)
    • toBufferedImage

      public static java.awt.image.BufferedImage toBufferedImage​(java.awt.Image img)
    • toCompatibleImage

      public static java.awt.image.BufferedImage toCompatibleImage​(java.awt.image.BufferedImage image)