public abstract class ImageIO extends Object
Modifier and Type | Field and Description |
---|---|
static String |
FORMAT_JPEG
Indicates the JPEG output format
|
static String |
FORMAT_PNG
Indicates the PNG output format
|
Constructor and Description |
---|
ImageIO() |
Modifier and Type | Method and Description |
---|---|
static ImageIO |
getImageIO()
Gets the ImageIO instance
|
Dimension |
getImageSize(String imageFilePath)
Returns the image size in pixels
|
abstract boolean |
isFormatSupported(String format)
Indicates if the given format for output is supported by this implementation
|
void |
save(Image img,
OutputStream response,
String format,
float quality)
Saves an image object to the given format
|
abstract void |
save(InputStream image,
OutputStream response,
String format,
int width,
int height,
float quality)
Saves an image file at the given resolution, scaling if necessary
|
void |
save(String imageFilePath,
OutputStream response,
String format,
int width,
int height,
float quality)
Saves an image file at the given resolution, scaling if necessary
|
String |
saveAndKeepAspect(String imageFilePath,
String preferredOutputPath,
String format,
int width,
int height,
float quality,
boolean onlyDownscale,
boolean scaleToFill)
Scales an image on disk while maintaining an aspect ratio, the appropriate aspect size will be
picked based on the status of scaleToFill
|
protected abstract void |
saveImage(Image img,
OutputStream response,
String format,
float quality)
Saves an image object to the given format
|
public static final String FORMAT_JPEG
public static final String FORMAT_PNG
public abstract void save(InputStream image, OutputStream response, String format, int width, int height, float quality) throws IOException
image
- source image streamresponse
- resulting image output will be written to this streamformat
- the format for the image either FORMAT_PNG or FORMAT_JPEGwidth
- the width for the resulting image, use -1 to not scaleheight
- the height of the resulting image, use -1 to not scalequality
- the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
this isn't implemented in all platforms.IOException
public void save(Image img, OutputStream response, String format, float quality) throws IOException
img
- the image objectresponse
- resulting image output will be written to this streamformat
- the format for the image either FORMAT_PNG or FORMAT_JPEGquality
- the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
this isn't implemented in all platforms.IOException
public void save(String imageFilePath, OutputStream response, String format, int width, int height, float quality) throws IOException
imageFilePath
- the image file pathresponse
- resulting image output will be written to this streamformat
- the format for the image either FORMAT_PNG or FORMAT_JPEGwidth
- the width for the resulting image, use -1 to not scaleheight
- the height of the resulting image, use -1 to not scalequality
- the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
this isn't implemented in all platforms.IOException
public Dimension getImageSize(String imageFilePath) throws IOException
imageFilePath
- the path to the imageIOException
public String saveAndKeepAspect(String imageFilePath, String preferredOutputPath, String format, int width, int height, float quality, boolean onlyDownscale, boolean scaleToFill) throws IOException
imageFilePath
- the path to the imagepreferredOutputPath
- the url where the image will be savedformat
- the format for the image either FORMAT_JPEG or FORMAT_PNGwidth
- the desired width, either width or height will be respected based on aspect dimensionsheight
- the desired height, either width or height will be respected based on aspect dimensionsquality
- the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
this isn't implemented in all platforms.onlyDownscale
- will not scale if the resolution to scale will be higher in this case will return the imageFilePathscaleToFill
- when set to true will pick the larger value so the resulting image will be at least as big as width x height, when set to false
will create an image that is no bigger than width x heightIOException
- if the operation failsprotected abstract void saveImage(Image img, OutputStream response, String format, float quality) throws IOException
img
- the image objectresponse
- resulting image output will be written to this streamformat
- the format for the image either FORMAT_PNG or FORMAT_JPEGquality
- the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
this isn't implemented in all platforms.IOException
public abstract boolean isFormatSupported(String format)
format
- the format for the image either FORMAT_PNG or FORMAT_JPEGpublic static ImageIO getImageIO()