Package megamek.common.util
Class ImageUtil
java.lang.Object
megamek.common.util.ImageUtil
Generic utility methods for image data
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImageLoader that loads sub-regions from a larger atlas file, but is given file names that are mapped into an atlas.static classImageLoader implementation that expects a path to an image file, and that file is loaded directly and the loaded image is returned.static interfaceInterface that defines methods for an ImageLoader.static classImageLoader that loads sub-regions from a larger atlas file. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic BufferedImageHolds a drawn "fail" image that can be used when image loading fails.static final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddImageLoader(ImageUtil.ImageLoader loader) Deprecated, for removal: This API element is subject to removal in a future version.static Stringbase64TextEncodeImage(Image image) takes an image and converts it to text in the Base64 encoding.static BufferedImageconvertToBufferedImage(Image image) Converts the given image to a BufferedImage.static BufferedImagecreateAcceleratedImage(int w, int h) static BufferedImagecreateAcceleratedImage(Image base) static voidcreateDoubleBlindHiddenImage(Map<Integer, String> imgCache) creates a ? image, used when units are hidden in double-blindstatic BufferedImageReturns a standard size (84x72) "fail" image having a red on white cross.static BufferedImageReturns a scaled version of the given image.static KernelgetGaussKernel(int width, float sigma) Returns a square normalized Kernel for a Gaussian Blur.static BufferedImagegetScaledImage(Image img, int newWidth, int newHeight) static BufferedImagegetScaledImage(Image img, int newWidth, int newHeight, int scaleType) static ImageloadImageFromFile(String fileName) Loads and returns the image of the given fileName.static ImageloadImageFromFile(MegaMekFile file) Loads and returns the image of the given fileName.
-
Field Details
-
IMAGE_SCALE_BICUBIC
public static final int IMAGE_SCALE_BICUBIC- See Also:
-
IMAGE_SCALE_AVG_FILTER
public static final int IMAGE_SCALE_AVG_FILTER- See Also:
-
failStandardImage
Holds a drawn "fail" image that can be used when image loading fails.
-
-
Method Details
-
createAcceleratedImage
- Returns:
- an image in a format best fitting for hardware acceleration, if possible, else just the image passed to it
-
createAcceleratedImage
- Returns:
- an image in a format best fitting for hardware acceleration, if possible
-
failStandardImage
Returns a standard size (84x72) "fail" image having a red on white cross. The image is drawn, not loaded and should therefore work in almost all cases. -
getScaledImage
- Parameters:
img-ImageImage to scale.newWidth- Width to scale tonewHeight- Height to scale to.- Returns:
- Get a scaled version of the input image.
-
convertToBufferedImage
Converts the given image to a BufferedImage. If it already is a BufferedImage, the image is only returned with a type cast without doing any further conversion.- Parameters:
image- An Image of any type- Returns:
- The image as a BufferedImage
-
fitImage
Returns a scaled version of the given image. Scaling is adjusted so that the image fits in the given maximum width and maximum height, keeping the aspect ratio of the image. Either the height or the width of the resulting image will be equal to the given max width or height, while the other value will be smaller than the given maximum. Uses the supplied scaling method.- Parameters:
image- The image to scalemaxWidth- The maximum width of the resulting imagemaxHeight- The maximum height of the resulting imagescaleType- The scale type,IMAGE_SCALE_BICUBICorIMAGE_SCALE_AVG_FILTER- Returns:
- A scaled image fitting in a rectangle of the size (maxWidth, maxHeight)
-
getScaledImage
- Parameters:
img-ImageImage to scale.newWidth- Width to scale tonewHeight- Height to scale toscaleType- Type of scaling to do.- Returns:
- scaled version of the input image, using the supplied type to select which scaling method to use.
-
addImageLoader
@Deprecated(since="0.51.0", forRemoval=true) public static void addImageLoader(ImageUtil.ImageLoader loader) Deprecated, for removal: This API element is subject to removal in a future version.Add a new image loader to the first position of the list, if it isn't there already -
loadImageFromFile
Loads and returns the image of the given fileName. This method does not make sure the image is fully loaded, this must be done by the caller when necessary (the simplest way is to create a new ImageIcon with the image). If the image cannot be loaded for any reason, the method returns a placeholder image but not null.- Parameters:
fileName- The image filename- Returns:
- The image if possible, a placeholder image otherwise
-
loadImageFromFile
Loads and returns the image of the given fileName. This method does not make sure the image is fully loaded, this must be done by the caller when necessary (the simplest way is to create a new ImageIcon with the image). If the image cannot be loaded for any reason, the method returns a placeholder image but not null.- Parameters:
file- The image as a MegaMekFile- Returns:
- The image if possible, a placeholder image otherwise
-
base64TextEncodeImage
takes an image and converts it to text in the Base64 encoding. When the given image is null, an empty String is returned. -
createDoubleBlindHiddenImage
creates a ? image, used when units are hidden in double-blind -
getGaussKernel
Returns a square normalized Kernel for a Gaussian Blur. The Kernel has width x width elements. Sigma gives its Gauss sharpness. A high sigma of e.g. 1000 returns a flat Kernel of equal elements (= 1 / width ^ 2); sigma should not be smaller than about 0.2 (will lead to an exception). Normal sigma values are in the area of 1 to 5.- Parameters:
width- The length and height of the Kernelsigma- The extent of the Gaussian- Returns:
- A Kernel
- See Also:
-