ImageUtil

Methods
17
Fields
None

Methods

MethodReturnsDescription
bufferedImageFromImage(Image)BufferedImageThe image itself: every Bento image is already a BufferedImage.
toARGB(Image)BufferedImageThe image itself when its type is TYPE_INT_ARGB, else a TYPE_INT_ARGB image it is drawn into (a decoded PNG, a premultiplied or 4-byte…
recolorImage(Image, Color)BufferedImageEvery pixel color, keeping its alpha.
luminanceOffset(Image, number)BufferedImageoffset added to red, green and blue, clamped.
luminanceScale(Image, number)BufferedImageRed, green and blue scaled by percentage, clamped.
alphaOffset(Image, number)BufferedImage(Image, number) -> BufferedImage: offset added to alpha, clamped. The two overloads are told apart by the number: a whole number (50,…
grayscaleImage(BufferedImage)BufferedImageA greyed copy, as Swing's disabled icons (GrayFilter, brighter, 50%).
resizeImage(BufferedImage, number, number)BufferedImage(BufferedImage, number, number) -> BufferedImage: A smoothly scaled (area-averaged) copy of the given size.
resizeImage(BufferedImage, number, number, boolean)BufferedImage
resizeCanvas(BufferedImage, number, number)BufferedImageThe image centred on a transparent canvas of the given size.
rotateImage(BufferedImage, number)BufferedImageThe image rotated theta radians about its centre, on a canvas the size of its rotated bounds, of the image's type when that has alpha (`T…
flipImage(BufferedImage, boolean, boolean)BufferedImageA mirrored copy.
outlineImage(BufferedImage, Color)BufferedImage(BufferedImage, Color) -> BufferedImage: The image with a one-pixel color outline, corners left out.
outlineImage(BufferedImage, Color, boolean)BufferedImage
fillImage(BufferedImage, Color)BufferedImageEvery non-transparent pixel color.
loadImageResource(any?, string)BufferedImage?An image resource: path resolved against the class c. A relative path with the plugin's own class (pass the plugin object, a panel, or…
getImageSpritePixels(BufferedImage, Client)SpritePixelsThe image as SpritePixels: its ARGB pixels, every fully transparent one 0. Pass the client global.
getImageIndexedSprite(BufferedImage, Client)IndexedSpriteThe image as an IndexedSprite (a chat icon for client:getModIcons()): a palette of its fully opaque colours after an unused entry 0, ev…
fromBytes(string)BufferedImage?The image encoded in data (a byte string, e.g. an HTTP body or Asset.bytes), or nil when it is not one, with the type and samples `lo…

Method details

toARGB

toARGB: (Image) -> BufferedImage

The image itself when its type is TYPE_INT_ARGB, else a TYPE_INT_ARGB image it is drawn into (a decoded PNG, a premultiplied or 4-byte ABGR image): a transparent pixel comes out 0 and a faint pixel's colour is rounded.

alphaOffset

alphaOffset: (Image, number) -> BufferedImage

(Image, number) -> BufferedImage: offset added to alpha, clamped. The two overloads are told apart by the number: a whole number (50, and also 1.0) is this one.

(Image, number) -> BufferedImage: Alpha scaled by percentage, clamped. Reached with a fractional number (0.5); a whole number reaches the int overload.

resizeImage

resizeImage: ((BufferedImage, number, number) -> BufferedImage) & ((BufferedImage, number, number, boolean) -> BufferedImage)

(BufferedImage, number, number) -> BufferedImage: A smoothly scaled (area-averaged) copy of the given size.

(BufferedImage, number, number, boolean) -> BufferedImage: A smoothly scaled copy; with preserveAspectRatio, the longer side fits and the other keeps the ratio.

rotateImage

rotateImage: (BufferedImage, number) -> BufferedImage

The image rotated theta radians about its centre, on a canvas the size of its rotated bounds, of the image's type when that has alpha (TYPE_4BYTE_ABGR for an RGBA PNG), else TYPE_INT_ARGB.

loadImageResource

loadImageResource: (any?, string) -> BufferedImage?

An image resource: path resolved against the class c. A relative path with the plugin's own class (pass the plugin object, a panel, or nil) is the plugin's package, whose resources are its assets/ folder: notes_icon.png reads assets/notes_icon.png (then the package root, so assets/notes_icon.png also works). A relative path with a built-in class (AlternateSprites, ColorScheme, or one Bento has no global for, by its name as a string: "IconTextField") is the built-in resource in that class's package. /x.png is the resource root: the built-in shared resources first (/util/reset.png, /util/arrow_right.png, /skill_icons/attack.png), then the plugin's assets/x.png. A missing file is an IllegalArgumentException (x.png is not found); a file that is not a PNG is nil (Bento decodes PNG only). The image's getType() is what the PNG decodes to (TYPE_4BYTE_ABGR for an RGBA PNG, TYPE_CUSTOM for grey and alpha), and a grey PNG's samples are answered through the grey curve (a sample of 98 is 167).

getImageIndexedSprite

getImageIndexedSprite: (BufferedImage, Client) -> IndexedSprite

The image as an IndexedSprite (a chat icon for client:getModIcons()): a palette of its fully opaque colours after an unused entry 0, every other pixel transparent (index 0), its sizes, no offsets. Opaque black finds the unused entry 0, so it is transparent. More than 255 colours raises. Pass the client global.

fromBytes

fromBytes: (string) -> BufferedImage?

The image encoded in data (a byte string, e.g. an HTTP body or Asset.bytes), or nil when it is not one, with the type and samples loadImageResource gives. Bento decodes PNG only.