public final class PngUtils extends Object
Modifier and Type | Method and Description |
---|---|
static BufferedImage |
getScaledInstance(BufferedImage img,
int targetWidth,
int targetHeight,
Object hint,
boolean higherQuality)
Convenience method that returns a scaled instance of the
provided
BufferedImage . |
static void |
resizePng(File image)
Creates a thumbnail copy of provided image, prefixed with "thumb_".
|
static void |
setDpi(File image)
Set the DPI on
image to 160. |
static void |
setDpi(File image,
int dotsPerInch)
Set the DPI on
image to dotsPerInch . |
static void |
setSafeDpi(File image,
int maxHeightInInches)
Set the DPI on
image so that it fits in maxHeightInInches ,
or to 160 if short enough. |
public static void resizePng(File image) throws IOException
image
- image file.IOException
- Failed to read the image or to write the thumbnail.public static BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean higherQuality)
BufferedImage
.img
- the original image to be scaledtargetWidth
- the desired width of the scaled instance,
in pixelstargetHeight
- the desired height of the scaled instance,
in pixelshint
- one of the rendering hints that corresponds to
RenderingHints.KEY_INTERPOLATION
(e.g.
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
,
RenderingHints.VALUE_INTERPOLATION_BILINEAR
,
RenderingHints.VALUE_INTERPOLATION_BICUBIC
)higherQuality
- if true, this method will use a multi-step
scaling technique that provides higher quality than the usual
one-step technique (only useful in downscaling cases, where
targetWidth
or targetHeight
is
smaller than the original dimensions, and generally only when
the BILINEAR
hint is specified)BufferedImage
public static void setSafeDpi(File image, int maxHeightInInches) throws IOException
image
so that it fits in maxHeightInInches
,
or to 160 if short enough.image
- PNG image file.maxHeightInInches
- maximum available image height in inches.IOException
- Failed to save the image.public static void setDpi(File image) throws IOException
image
to 160.image
- PNG image file.IOException
- Failed to save the image.public static void setDpi(File image, int dotsPerInch) throws IOException
image
to dotsPerInch
.image
- PNG image file.dotsPerInch
- DPI to set in metadata.IOException
- Failed to save the image.Copyright © 2025 Open Identity Platform Community. All rights reserved.