Class IconHelper
java.lang.Object
de.rcblum.stream.deck.util.IconHelper
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final SDImagestatic final SDImagestatic final FontDefault font for the text on the ESD FantasqueSansMono-Bold.ttf /resources/Blogger-Sans-Medium.ttf /resources/FantasqueSansMono-Bold.ttfstatic final SDImagestatic final BufferedImagestatic final Stringstatic final Stringstatic final intPosition to place the text bottom the top of the iconstatic final intPosition to place the text at the center of the iconstatic final intPosition to place the text at the top of the icon -
Method Summary
Modifier and TypeMethodDescriptionstatic SDImageAdds a text to a copy of the given image.static SDImageAdds a text to a copy of the given image.static SDImageaddText(BufferedImage imgData, String text, int pos) Adds a text to a copy of the given image.static SDImageaddText(BufferedImage imgData, String text, int pos, float fontSize) Adds a text to a copy of the given image.static voidapplyAlpha(BufferedImage image, BufferedImage mask) static BufferedImageapplyFrame(BufferedImage img, Color frameColor) Applies a frame with the default frame color.static SDImageapplyImage(SDImage imgData, BufferedImage apply) Applies a normal BufferedImage to an already BGR converted image in byte formstatic SDImagecacheImage(String path, BufferedImage img) Converts given image to bgr color schema and caches the resulting image data.static SDImageConverts 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).static SDImageconvertImage(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).static SDImageconvertImageAndApplyFrame(BufferedImage src, Color frameColor) static BufferedImagestatic SDImagecreateColoredFrame(Color borderColor) static SDImagecreateFolderImage(Color background, boolean applyFrame, Color frameColor) static voidcreateIconPackage(String pathToArchive, String pathToIcon, String[] pathToFrames, AnimationStack stack) static IconPackagecreateIconPackage(String pathToArchive, String pathToIcon, String pathToGif, AnimationStack stack, Dimension targetSize, boolean useCache) Packs an icon and the associated animation frames and timing into one usable archive.static BufferedImagecreateResizedCopy(BufferedImage originalImage, boolean preserveType, Dimension dimensions) static AnimationStackcreateRollingTextAnimation(SDImage imgData, String text, int pos) static AnimationStackcreateRollingTextAnimation(SDImage imgData, String text, int pos, float fontSize) Creates an animation with running textstatic BufferedImagefillBackground(BufferedImage img, Color color) static BufferedImageflipHoriz(BufferedImage image) static SDImagegetCachedImage(String path) Retunrs a previous cached image to the given Stringstatic SDImagestatic BufferedImagegetImageFromResource(String fileName) Loads an image from the jar file.static intstatic intstatic IconPackageloadIconPackage(String pathToZip) static IconPackageloadIconPackage(String pathToZip, Dimension resizeTo) static SDImagestatic SDImagestatic SDImageloadImage(String path, InputStream inputStream, boolean disableCache, boolean applyFrame, Color frameColor) static SDImagestatic SDImagestatic SDImageloadImageFromResource(String path) Loads and converts an image from the jar file ito na dispalyable Icon for the StreamDeckstatic SDImagestatic SDImageloadImageSafe(String path) static SDImageloadImageSafe(String path, boolean applyFrame, Color frameColor) static SDImageloadImageSafe(Path path) static SDImageloadImageSafe(Path path, boolean applyFrame, Color frameColor) static SDImage[]loadImagesFromGif(String pathToGif, boolean useCache) static BufferedImageloadRawImage(InputStream inputStream) static BufferedImageloadRawImage(Path path) static BufferedImagerotate180(BufferedImage inputImage) static voidsetRollingTextPadding(int rollingTextPadding) static voidsetTextBoxAlphaValue(int textBoxAlphaValue) static ByteArrayOutputStreamstatic ByteArrayOutputStream
-
Field Details
-
TEMP_BLACK_ICON
- See Also:
-
TEMP_BLACK_TOUCH_SCREEN
- See Also:
-
FRAME
-
TEXT_TOP
public static final int TEXT_TOPPosition to place the text at the top of the icon- See Also:
-
TEXT_CENTER
public static final int TEXT_CENTERPosition to place the text at the center of the icon- See Also:
-
TEXT_BOTTOM
public static final int TEXT_BOTTOMPosition to place the text bottom the top of the icon- See Also:
-
DEFAULT_FONT
Default font for the text on the ESD FantasqueSansMono-Bold.ttf /resources/Blogger-Sans-Medium.ttf /resources/FantasqueSansMono-Bold.ttf -
BLACK_ICON
-
BLACK_TOUCH_SCREEN
-
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
-
createColoredFrame
-
applyAlpha
-
copyBufferedImage
-
addText
Adds a text to a copy of the given image. Position of the text can be influenced bypos. 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, seeTEXT_TOP,TEXT_CENTER,TEXT_BOTTOM)- Returns:
- byte array with the image where the text was added
-
addText
Adds a text to a copy of the given image. Position of the text can be influenced bypos. 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, seeTEXT_TOP,TEXT_CENTER,TEXT_BOTTOM)- Returns:
- byte array with the image where the text was added
-
addText
Adds a text to a copy of the given image. Position of the text can be influenced bypos. 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, seeTEXT_TOP,TEXT_CENTER,TEXT_BOTTOM)fontSize- Size of the font to use- Returns:
- byte array with the image where the text was added
-
addText
Adds a text to a copy of the given image. Position of the text can be influenced bypos. 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, seeTEXT_TOP,TEXT_CENTER,TEXT_BOTTOM)fontSize- Size of the font to use- Returns:
- byte array with the image where the text was added
-
createRollingTextAnimation
-
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, seeTEXT_TOP,TEXT_CENTER,TEXT_BOTTOM)fontSize- Size of the font to use- Returns:
- byte array with the image where the text was added
-
getCachedImage
-
cacheImage
Converts given image to bgr color schema and caches the resulting image data.- Parameters:
path- Path to be cachesimg- Image to be cached, must be fo TYPE_INT_*RGB*- Returns:
- Returns the cached image data
-
convertImage
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
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
-
applyImage
Applies a normal BufferedImage to an already BGR converted image in byte form- Parameters:
imgData- base image as byte arrayapply- image to be applied- Returns:
- SDImage with the applied image
-
applyFrame
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 createdpathToIcon- Icon that should normaly be displayed on one or multiple keys on the stream deck.pathToGif- Gif, that contains the animationstack- AnimationStack to include into the icon packageuseCache- Use image caching or not- Returns:
- Returns the created IconPackage
- Throws:
URISyntaxException- Maleformed archive URIIOException- If writing to the created archive fails
-
createIconPackage
public static void createIconPackage(String pathToArchive, String pathToIcon, String[] pathToFrames, AnimationStack stack) throws URISyntaxException, IOException - Throws:
URISyntaxExceptionIOException
-
createResizedCopy
public static BufferedImage createResizedCopy(BufferedImage originalImage, boolean preserveType, Dimension dimensions) -
fillBackground
-
flipHoriz
-
getImage
-
getImageFromResource
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
- Throws:
IOExceptionURISyntaxException
-
loadIconPackage
public static IconPackage loadIconPackage(String pathToZip, Dimension resizeTo) throws IOException, URISyntaxException - Throws:
IOExceptionURISyntaxException
-
loadImageSafe
-
loadImageSafe
-
loadImageSafe
-
loadImageSafe
-
loadImage
- Throws:
IOException
-
loadImage
- Throws:
IOException
-
loadImage
- 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
- Throws:
IOException
-
loadRawImage
- Throws:
IOException
-
loadImageFromResource
-
loadImageFromResourceSafe
-
loadImagesFromGif
- Throws:
IOException
-
rotate180
-