Package net.runelite.client.util
Class ImageUtil
- java.lang.Object
-
- net.runelite.client.util.ImageUtil
-
public class ImageUtil extends java.lang.ObjectVarious Image/BufferedImage utilities.
-
-
Constructor Summary
Constructors Constructor Description ImageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.awt.image.BufferedImagealphaOffset(java.awt.Image rawImg, float percentage)Offsets an image's alpha component by a given percentage.static java.awt.image.BufferedImagealphaOffset(java.awt.Image rawImg, int offset)Offsets an image's alpha component by a given offset.static java.awt.image.BufferedImagebufferedImageFromImage(java.awt.Image image)Creates aBufferedImagefrom anImage.static java.awt.image.BufferedImagefillImage(java.awt.image.BufferedImage image, java.awt.Color color)Fills all non-transparent pixels of the given image with the given color.static java.awt.image.BufferedImageflipImage(java.awt.image.BufferedImage image, boolean horizontal, boolean vertical)Flips an image horizontally and/or vertically.static net.runelite.api.IndexedSpritegetImageIndexedSprite(java.awt.image.BufferedImage image, net.runelite.api.Client client)Converts an image into anIndexedSpriteinstance.static net.runelite.api.SpritePixelsgetImageSpritePixels(java.awt.image.BufferedImage image, net.runelite.api.Client client)Converts the buffered image into a sprite image and returns itstatic java.awt.image.BufferedImagegetResourceStreamFromClass(java.lang.Class<?> c, java.lang.String path)Deprecated.static java.awt.image.BufferedImagegrayscaleImage(java.awt.image.BufferedImage image)Creates a grayscale image from the given image.static java.awt.image.BufferedImageloadImageResource(java.lang.Class<?> c, java.lang.String path)Reads an image resource from a given path relative to a given class.static java.awt.image.BufferedImageluminanceOffset(java.awt.Image rawImg, int offset)Offsets an image's luminance by a given value.static java.awt.image.BufferedImageluminanceScale(java.awt.Image rawImg, float percentage)Changes an images luminance by a scaling factorstatic java.awt.image.BufferedImageoutlineImage(java.awt.image.BufferedImage image, java.awt.Color color)Outlines non-transparent pixels of a BufferedImage with the given color.static java.awt.image.BufferedImageoutlineImage(java.awt.image.BufferedImage image, java.awt.Color color, java.lang.Boolean outlineCorners)Outlines non-transparent pixels of a BufferedImage with the given color.static java.awt.image.BufferedImagerecolorImage(java.awt.Image image, java.awt.Color rgb)Creates a new image with the same alpha channel, but a constant RGB channelstatic java.awt.image.BufferedImageresizeCanvas(java.awt.image.BufferedImage image, int newWidth, int newHeight)Re-size a BufferedImage's canvas to the given dimensions.static java.awt.image.BufferedImageresizeImage(java.awt.image.BufferedImage image, int newWidth, int newHeight)Re-size a BufferedImage to the given dimensions.static java.awt.image.BufferedImageresizeImage(java.awt.image.BufferedImage image, int newWidth, int newHeight, boolean preserveAspectRatio)Re-size a BufferedImage to the given dimensions.static java.awt.image.BufferedImagerotateImage(java.awt.image.BufferedImage image, double theta)Rotates an image around its center by a given number of radians.static java.awt.image.BufferedImagetoARGB(java.awt.Image image)Creates an ARGBBufferedImagefrom anImage.
-
-
-
Method Detail
-
bufferedImageFromImage
public static java.awt.image.BufferedImage bufferedImageFromImage(java.awt.Image image)
Creates aBufferedImagefrom anImage.- Parameters:
image- An Image to be converted to a BufferedImage.- Returns:
- A BufferedImage instance of the same given image.
-
toARGB
public static java.awt.image.BufferedImage toARGB(java.awt.Image image)
Creates an ARGBBufferedImagefrom anImage.
-
recolorImage
public static java.awt.image.BufferedImage recolorImage(java.awt.Image image, java.awt.Color rgb)Creates a new image with the same alpha channel, but a constant RGB channel
-
luminanceOffset
public static java.awt.image.BufferedImage luminanceOffset(java.awt.Image rawImg, int offset)Offsets an image's luminance by a given value.- Parameters:
rawImg- The image to be darkened or brightened.offset- A signed 8-bit integer value to brighten or darken the image with. Values above 0 will brighten, and values below 0 will darken.- Returns:
- The given image with its brightness adjusted by the given offset.
-
luminanceScale
public static java.awt.image.BufferedImage luminanceScale(java.awt.Image rawImg, float percentage)Changes an images luminance by a scaling factor- Parameters:
rawImg- The image to be darkened or brightened.percentage- The ratio to darken or brighten the given image. Values above 1 will brighten, and values below 1 will darken.- Returns:
- The given image with its brightness scaled by the given percentage.
-
alphaOffset
public static java.awt.image.BufferedImage alphaOffset(java.awt.Image rawImg, int offset)Offsets an image's alpha component by a given offset.- Parameters:
rawImg- The image to be made more or less transparent.offset- A signed 8-bit integer value to modify the image's alpha component with. Values above 0 will increase transparency, and values below 0 will decrease transparency.- Returns:
- The given image with its alpha component adjusted by the given offset.
-
alphaOffset
public static java.awt.image.BufferedImage alphaOffset(java.awt.Image rawImg, float percentage)Offsets an image's alpha component by a given percentage.- Parameters:
rawImg- The image to be made more or less transparent.percentage- The ratio to modify the image's alpha component with. Values above 1 will increase transparency, and values below 1 will decrease transparency.- Returns:
- The given image with its alpha component scaled by the given percentage.
-
grayscaleImage
public static java.awt.image.BufferedImage grayscaleImage(java.awt.image.BufferedImage image)
Creates a grayscale image from the given image.- Parameters:
image- The source image to be converted.- Returns:
- A copy of the given imnage, with colors converted to grayscale.
-
resizeImage
public static java.awt.image.BufferedImage resizeImage(java.awt.image.BufferedImage image, int newWidth, int newHeight)Re-size a BufferedImage to the given dimensions.- Parameters:
image- the BufferedImage.newWidth- The width to set the BufferedImage to.newHeight- The height to set the BufferedImage to.- Returns:
- The BufferedImage with the specified dimensions
-
resizeImage
public static java.awt.image.BufferedImage resizeImage(java.awt.image.BufferedImage image, int newWidth, int newHeight, boolean preserveAspectRatio)Re-size a BufferedImage to the given dimensions.- Parameters:
image- the BufferedImage.newWidth- The width to set the BufferedImage to.newHeight- The height to set the BufferedImage to.preserveAspectRatio- Whether to preserve the original image's aspect ratio. Whentrue, the image will be scaled to have a maximum ofnewWidthwidth andnewHeightheight.- Returns:
- The BufferedImage with the specified dimensions
-
resizeCanvas
public static java.awt.image.BufferedImage resizeCanvas(java.awt.image.BufferedImage image, int newWidth, int newHeight)Re-size a BufferedImage's canvas to the given dimensions.- Parameters:
image- The image whose canvas should be re-sized.newWidth- The width to set the BufferedImage to.newHeight- The height to set the BufferedImage to.- Returns:
- The BufferedImage centered within canvas of given dimensions.
-
rotateImage
public static java.awt.image.BufferedImage rotateImage(java.awt.image.BufferedImage image, double theta)Rotates an image around its center by a given number of radians.- Parameters:
image- The image to be rotated.theta- The number of radians to rotate the image.- Returns:
- The given image, rotated by the given theta.
-
flipImage
public static java.awt.image.BufferedImage flipImage(java.awt.image.BufferedImage image, boolean horizontal, boolean vertical)Flips an image horizontally and/or vertically.- Parameters:
image- The image to be flipped.horizontal- Whether the image should be flipped horizontally.vertical- Whether the image should be flipped vertically.- Returns:
- The given image, flipped horizontally and/or vertically.
-
outlineImage
public static java.awt.image.BufferedImage outlineImage(java.awt.image.BufferedImage image, java.awt.Color color)Outlines non-transparent pixels of a BufferedImage with the given color.- Parameters:
image- The image to be outlined.color- The color to use for the outline.- Returns:
- The BufferedImage with its edges outlined with the given color.
-
outlineImage
public static java.awt.image.BufferedImage outlineImage(java.awt.image.BufferedImage image, java.awt.Color color, java.lang.Boolean outlineCorners)Outlines non-transparent pixels of a BufferedImage with the given color. Optionally outlines corners in addition to edges.- Parameters:
image- The image to be outlined.color- The color to use for the outline.outlineCorners- Whether to draw an outline around corners, or only around edges.- Returns:
- The BufferedImage with its edges--and optionally, corners--outlined with the given color.
-
getResourceStreamFromClass
@Deprecated public static java.awt.image.BufferedImage getResourceStreamFromClass(java.lang.Class<?> c, java.lang.String path)Deprecated.- See Also:
loadImageResource(Class, String)
-
loadImageResource
public static java.awt.image.BufferedImage loadImageResource(java.lang.Class<?> c, java.lang.String path)Reads an image resource from a given path relative to a given class. This method is primarily shorthand for the synchronization and error handling required for loading image resources from the classpath.- Parameters:
c- The class to be referenced for the package path.path- The path, relative to the given class.- Returns:
- A
BufferedImageof the loaded image resource from the given path.
-
fillImage
public static java.awt.image.BufferedImage fillImage(java.awt.image.BufferedImage image, java.awt.Color color)Fills all non-transparent pixels of the given image with the given color.- Parameters:
image- The image which should have its non-transparent pixels filled.color- The color with which to fill pixels.- Returns:
- The given image with all non-transparent pixels set to the given color.
-
getImageSpritePixels
public static net.runelite.api.SpritePixels getImageSpritePixels(java.awt.image.BufferedImage image, net.runelite.api.Client client)Converts the buffered image into a sprite image and returns it- Parameters:
image- The image to be convertedclient- Current client instance- Returns:
- The buffered image as a sprite image
-
getImageIndexedSprite
public static net.runelite.api.IndexedSprite getImageIndexedSprite(java.awt.image.BufferedImage image, net.runelite.api.Client client)Converts an image into anIndexedSpriteinstance. The passed in image can only have at max 255 different colors.- Parameters:
image- The image to be convertedclient- Current client instance- Returns:
- The image as an
IndexedSprite
-
-