Class ImageTextUtil

java.lang.Object
ca.corbett.extras.image.ImageTextUtil

public final class ImageTextUtil extends Object
Contains utility method for drawing stylized text onto a BufferedImage. Absorbed into sc-util as per UTIL-143.
Since:
2023-11-11
Author:
scorbo2
  • Field Details

    • DEFAULT_LINE_LENGTH

      public static final int DEFAULT_LINE_LENGTH
      See Also:
    • DEFAULT_FONT

      public static final Font DEFAULT_FONT
    • DEFAULT_FILL_COLOR

      public static final Color DEFAULT_FILL_COLOR
    • DEFAULT_OUTLINE_COLOR

      public static final Color DEFAULT_OUTLINE_COLOR
    • DEFAULT_OUTLINE_WIDTH_FACTOR

      public static final float DEFAULT_OUTLINE_WIDTH_FACTOR
      See Also:
  • Method Details

    • drawText

      public static void drawText(BufferedImage image, String text)
      Shorthand for drawing text on an image with all default settings. The text will be centered in the image horizontally and vertically and will be line wrapped as needed.
      Parameters:
      image - The image on which to draw.
      text - The text to be rendered.
    • drawText

      public static void drawText(BufferedImage image, String text, Font font, Color outlineColor, Color fillColor)
      Shorthand for drawing text on an image with the given font styling properties. The text will be centered within the image vertically and horizontally and will be line wrapped as needed.
      Parameters:
      image - The BufferedImage on which the text will be drawn.
      text - The text to be drawn. Can be arbitrarily long; linewrapping will be applied.
      font - The font to use.
      outlineColor - The Color to use for outlining the text (if necessary).
      fillColor - The color to use to fill the text.
    • drawText

      public static void drawText(BufferedImage image, String text, Font font, Color outlineColor, Color fillColor, ImageTextUtil.TextAlign align)
      Shorthand for drawing text on an image with the given font styling properties and alignment. The text will be line wrapped as needed.
      Parameters:
      image - The BufferedImage on which the text will be drawn.
      text - The text to be drawn. Can be arbitrarily long; linewrapping will be applied.
      font - The font to use.
      outlineColor - The Color to use for outlining the text (if necessary).
      fillColor - The color to use to fill the text.
      align - The desired alignment for the text within the image.
    • drawText

      public static void drawText(BufferedImage image, String text, int lineLength, Font font, ImageTextUtil.TextAlign align, Color outlineColor, float outlineWidthFactor, Color fillColor)
      Outputs the given lines of text using the given styling parameters. Text will be line wrapped and scaled as needed to fit in the image.
      Parameters:
      image - The BufferedImage on which the text will be drawn.
      text - The text to be drawn. Can be arbitrarily long; linewrapping will be applied.
      lineLength - The desired length of each line. Will be adjusted based on image dimensions.
      font - The font to use.
      align - A TextAlign value for placing the text within our rectangle.
      outlineColor - The Color to use for outlining the text (if necessary).
      outlineWidthFactor - fontPointSize/outlineWidthFactor determines thickness of text border.
      fillColor - The color to use to fill the text.
    • drawText

      public static void drawText(BufferedImage image, String text, int lineLength, Font font, ImageTextUtil.TextAlign align, Color outlineColor, float outlineWidthFactor, Color fillColor, BufferedImage fillTexture, Rectangle rect)
      Outputs the given lines of text using the given styling parameters and the given placement rectangle. Text will be line wrapped and scaled as needed to fit in the given Rectangle.
      Parameters:
      image - The BufferedImage on which the text will be drawn.
      text - The text to be drawn. Can be arbitrarily long; linewrapping will be applied.
      lineLength - The desired length of each line. Will be adjusted based on image dimensions.
      font - The font to use.
      align - A TextAlign value for placing the text within our rectangle.
      outlineColor - The Color to use for outlining the text (if necessary).
      outlineWidthFactor - fontPointSize/outlineWidthFactor determines thickness of text border.
      fillColor - The color to use to fill the text.
      fillTexture - An image to use to fill text (if fillColor is null, otherwise ignored).
      rect - The Rectangle in image coordinates in which the text will be drawn.