Class IconHelper

java.lang.Object
de.rcblum.stream.deck.util.IconHelper

public class IconHelper extends Object


MIT License Copyright (c) 2018 Roland von Werden Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Version:
1.0.2
Author:
Roland von Werden
  • Field Details

    • TEMP_BLACK_ICON

      public static final String TEMP_BLACK_ICON
      See Also:
    • TEMP_BLACK_TOUCH_SCREEN

      public static final String TEMP_BLACK_TOUCH_SCREEN
      See Also:
    • FRAME

      public static final BufferedImage FRAME
    • TEXT_TOP

      public static final int TEXT_TOP
      Position to place the text at the top of the icon
      See Also:
    • TEXT_CENTER

      public static final int TEXT_CENTER
      Position to place the text at the center of the icon
      See Also:
    • TEXT_BOTTOM

      public static final int TEXT_BOTTOM
      Position to place the text bottom the top of the icon
      See Also:
    • DEFAULT_FONT

      public static final Font DEFAULT_FONT
      Default font for the text on the ESD FantasqueSansMono-Bold.ttf /resources/Blogger-Sans-Medium.ttf /resources/FantasqueSansMono-Bold.ttf
    • BLACK_ICON

      public static final SDImage BLACK_ICON
    • BLACK_TOUCH_SCREEN

      public static final SDImage BLACK_TOUCH_SCREEN
    • FOLDER_ICON

      public static final SDImage FOLDER_ICON
  • Method Details

    • getTextBoxAlphaValue

      public static int getTextBoxAlphaValue()
    • setTextBoxAlphaValue

      public static void setTextBoxAlphaValue(int textBoxAlphaValue)
    • getRollingTextPadding

      public static int getRollingTextPadding()
    • setRollingTextPadding

      public static void setRollingTextPadding(int rollingTextPadding)
    • createFolderImage

      public static SDImage createFolderImage(Color background, boolean applyFrame, Color frameColor)
    • createColoredFrame

      public static SDImage createColoredFrame(Color borderColor)
    • applyAlpha

      public static void applyAlpha(BufferedImage image, BufferedImage mask)
    • copyBufferedImage

      public static BufferedImage copyBufferedImage(BufferedImage bi)
    • addText

      public static SDImage addText(SDImage imgData, String text, int pos)
      Adds a text to a copy of the given image. Position of the text can be influenced by pos. Text will be wrapped around the first space, if the text is to wide.
      Parameters:
      imgData - Image where the text should be added to.
      text - Text to be added to the image.
      pos - Position of the text (Top, Center, Bottom, see TEXT_TOP, TEXT_CENTER, TEXT_BOTTOM)
      Returns:
      byte array with the image where the text was added
    • addText

      public static SDImage addText(BufferedImage imgData, String text, int pos)
      Adds a text to a copy of the given image. Position of the text can be influenced by pos. Text will be wrapped around the first space, if the text is to wide.
      Parameters:
      imgData - Image where the text should be added to.
      text - Text to be added to the image.
      pos - Position of the text (Top, Center, Bottom, see TEXT_TOP, TEXT_CENTER, TEXT_BOTTOM)
      Returns:
      byte array with the image where the text was added
    • addText

      public static SDImage addText(SDImage imgData, String text, int pos, float fontSize)
      Adds a text to a copy of the given image. Position of the text can be influenced by pos. Text will be wrapped around the first space, if the text is to wide.
      Parameters:
      imgData - Image where the text should be added to.
      text - Text to be added to the image.
      pos - Position of the text (Top, Center, Bottom, see TEXT_TOP, TEXT_CENTER, TEXT_BOTTOM)
      fontSize - Size of the font to use
      Returns:
      byte array with the image where the text was added
    • addText

      public static SDImage addText(BufferedImage imgData, String text, int pos, float fontSize)
      Adds a text to a copy of the given image. Position of the text can be influenced by pos. Text will be wrapped around the first space, if the text is to wide.
      Parameters:
      imgData - Image where the text should be added to.
      text - Text to be added to the image.
      pos - Position of the text (Top, Center, Bottom, see TEXT_TOP, TEXT_CENTER, TEXT_BOTTOM)
      fontSize - Size of the font to use
      Returns:
      byte array with the image where the text was added
    • createRollingTextAnimation

      public static AnimationStack createRollingTextAnimation(SDImage imgData, String text, int pos)
    • createRollingTextAnimation

      public static AnimationStack createRollingTextAnimation(SDImage imgData, String text, int pos, float fontSize)
      Creates an animation with running text
      Parameters:
      imgData - Image where the text should be added to.
      text - Text to be added to the image.
      pos - Position of the text (Top, Center, Bottom, see TEXT_TOP, TEXT_CENTER, TEXT_BOTTOM)
      fontSize - Size of the font to use
      Returns:
      byte array with the image where the text was added
    • getCachedImage

      public static SDImage getCachedImage(String path)
      Retunrs a previous cached image to the given String
      Parameters:
      path - String under which the images could be cached
      Returns:
      Returns the cached image data or null, if it does not exist
    • cacheImage

      public static SDImage cacheImage(String path, BufferedImage img)
      Converts given image to bgr color schema and caches the resulting image data.
      Parameters:
      path - Path to be caches
      img - Image to be cached, must be fo TYPE_INT_*RGB*
      Returns:
      Returns the cached image data
    • convertImage

      public static SDImage convertImage(BufferedImage img)
      Converts the given image to the stream deck format.
      Format is:
      Color Schema: BGR
      Image size: 72 x 72 pixel
      Stored in an array with each byte stored seperatly (Size of each array is 72 x 72 x 3 = 15_552).
      Parameters:
      img - Image to be converted
      Returns:
      Byte arraythat contains the given image, ready to be sent to the stream deck
    • convertImage

      public static SDImage convertImage(BufferedImage img, Dimension dimensions)
      Converts the given image to the stream deck format.
      Format is:
      Color Schema: BGR
      Image size: 72 x 72 pixel
      Stored in an array with each byte stored seperatly (Size of each array is 72 x 72 x 3 = 15_552).
      Parameters:
      img - Image to be converted
      Returns:
      Byte arraythat contains the given image, ready to be sent to the stream deck
    • writeToByteArrayOutputStreamAsJpeg

      public static ByteArrayOutputStream writeToByteArrayOutputStreamAsJpeg(BufferedImage image) throws IOException
      Throws:
      IOException
    • writeToByteArrayOutputStreamAsJpeg85

      public static ByteArrayOutputStream writeToByteArrayOutputStreamAsJpeg85(BufferedImage image) throws IOException
      Throws:
      IOException
    • convertImageAndApplyFrame

      public static SDImage convertImageAndApplyFrame(BufferedImage src, Color frameColor)
    • applyImage

      public static SDImage applyImage(SDImage imgData, BufferedImage apply)
      Applies a normal BufferedImage to an already BGR converted image in byte form
      Parameters:
      imgData - base image as byte array
      apply - image to be applied
      Returns:
      SDImage with the applied image
    • applyFrame

      public static BufferedImage applyFrame(BufferedImage img, Color frameColor)
      Applies a frame with the default frame color. Will resize any image that is bigger than the bounds of the icons.
      Parameters:
      img - Image to apply the frame to.
      frameColor - Color of the frame.
      Returns:
      Image with the frame applied.
    • createIconPackage

      public static IconPackage createIconPackage(String pathToArchive, String pathToIcon, String pathToGif, AnimationStack stack, Dimension targetSize, boolean useCache) throws URISyntaxException, IOException
      Packs an icon and the associated animation frames and timing into one usable archive.
      Parameters:
      pathToArchive - Archive to be created
      pathToIcon - Icon that should normaly be displayed on one or multiple keys on the stream deck.
      pathToGif - Gif, that contains the animation
      stack - AnimationStack to include into the icon package
      useCache - Use image caching or not
      Returns:
      Returns the created IconPackage
      Throws:
      URISyntaxException - Maleformed archive URI
      IOException - If writing to the created archive fails
    • createIconPackage

      public static void createIconPackage(String pathToArchive, String pathToIcon, String[] pathToFrames, AnimationStack stack) throws URISyntaxException, IOException
      Throws:
      URISyntaxException
      IOException
    • createResizedCopy

      public static BufferedImage createResizedCopy(BufferedImage originalImage, boolean preserveType, Dimension dimensions)
    • fillBackground

      public static BufferedImage fillBackground(BufferedImage img, Color color)
    • flipHoriz

      public static BufferedImage flipHoriz(BufferedImage image)
    • getImage

      public static SDImage getImage(String string)
    • getImageFromResource

      public static BufferedImage getImageFromResource(String fileName)
      Loads an image from the jar file.
      Parameters:
      fileName - Path to image.
      Returns:
      A BufferedImage with the image from the jar file or null, if the image could not be loaded.
    • loadIconPackage

      public static IconPackage loadIconPackage(String pathToZip) throws IOException, URISyntaxException
      Throws:
      IOException
      URISyntaxException
    • loadIconPackage

      public static IconPackage loadIconPackage(String pathToZip, Dimension resizeTo) throws IOException, URISyntaxException
      Throws:
      IOException
      URISyntaxException
    • loadImageSafe

      public static SDImage loadImageSafe(String path)
    • loadImageSafe

      public static SDImage loadImageSafe(Path path)
    • loadImageSafe

      public static SDImage loadImageSafe(String path, boolean applyFrame, Color frameColor)
    • loadImageSafe

      public static SDImage loadImageSafe(Path path, boolean applyFrame, Color frameColor)
    • loadImage

      public static SDImage loadImage(Path path) throws IOException
      Throws:
      IOException
    • loadImage

      public static SDImage loadImage(String path) throws IOException
      Throws:
      IOException
    • loadImage

      public static SDImage loadImage(Path path, boolean applyFrame, Color frameColor) throws IOException
      Throws:
      IOException
    • loadImage

      public static SDImage loadImage(String path, boolean applyFrame, Color frameColor) throws IOException
      Throws:
      IOException
    • loadImage

      public static SDImage loadImage(String path, InputStream inputStream, boolean disableCache, boolean applyFrame, Color frameColor) throws IOException
      Throws:
      IOException
    • loadRawImage

      public static BufferedImage loadRawImage(Path path) throws IOException
      Throws:
      IOException
    • loadRawImage

      public static BufferedImage loadRawImage(InputStream inputStream) throws IOException
      Throws:
      IOException
    • loadImageFromResource

      public static SDImage loadImageFromResource(String path)
      Loads and converts an image from the jar file ito na dispalyable Icon for the StreamDeck
      Parameters:
      path - Path to icon
      Returns:
      A SDImage containg a displayabe icon or null, if the image could not be loaded.
    • loadImageFromResourceSafe

      public static SDImage loadImageFromResourceSafe(String path)
    • loadImagesFromGif

      public static SDImage[] loadImagesFromGif(String pathToGif, boolean useCache) throws IOException
      Throws:
      IOException
    • rotate180

      public static BufferedImage rotate180(BufferedImage inputImage)