Package com.dkt.graphics.utils
Class Utils
java.lang.Object
com.dkt.graphics.utils.Utils
- Author:
- Federico Vera <[email protected]>
-
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageDraws aGraphicEinto aBufferedImagestatic ColorgetColorWithAlpha(Color color, int alpha) Generates a newColorbased on the color but with the given alphastatic BufferedImageRetrieves a 1:1 image of the canvasstatic PaintgetTexture(String path) Generates a texture from a given filestatic voidsaveScreenshot(Canvas canvas, String path, boolean back) Saves a 1:1 screenshot of the canvas
The image is saved using thepngformat, so if the file doesn't end with.pngthe extension will be appendedstatic BufferedImagetrimImage(BufferedImage img, Color omit) Trims a given image to its minimum size without loosing any part of the drawing.
-
Method Details
-
getColorWithAlpha
Generates a newColorbased on the color but with the given alpha- Parameters:
color- the original coloralpha- the alpha value if the value is bigger than 255 it will be set to 255, and if the value is smaller than 0 then it will be set to 0- Returns:
- A new color with the same RGB value as the argument but with the specified alpha
- Throws:
IllegalArgumentException- if color isnull
-
saveScreenshot
Saves a 1:1 screenshot of the canvas
The image is saved using thepngformat, so if the file doesn't end with.pngthe extension will be appended- Parameters:
canvas- TheCanvasto printpath- The path of the fileback-trueif you want to paint the background andfalseotherwise (falseis needed when painting with transparent components.- Throws:
IOException- If the image can't be writtenIllegalArgumentException- If either the canvas or the path arenull
-
getImage
Retrieves a 1:1 image of the canvas- Parameters:
canvas- TheCanvasto printback-trueif you want to paint the background andfalseotherwise (falseis needed when painting with transparent components.- Returns:
- a
BufferedImagethe same size of the canvas - Throws:
IllegalArgumentException- If the canvas isnull
-
trimImage
Trims a given image to its minimum size without loosing any part of the drawing.- Parameters:
img- The image to trimomit- TheColorto omit when trimming (what to consider as not drawn). Usually isColor.WHITEornew Color(0, true)- Returns:
- a
BufferedImageresult of trimming the original image - Throws:
IllegalArgumentException- Ifimgisnull
-
getTexture
Generates a texture from a given file- Parameters:
path- the path of the image file- Returns:
- A
TexturePaintfor this file - Throws:
IOException- If the image can't be read or if the file isn't a valid imageIllegalArgumentException- If the path isnull
-
draw
Draws aGraphicEinto aBufferedImage- Parameters:
e- element to draww- width of the imageh- height of the image- Returns:
- a
BufferedImagethat represents theGraphicE
-