public abstract class ImageIO
- Object
- ImageIO
Enable simple operations on image file & image objects such as dynamic scaling
and storage to binary formats such as JPEG. Use Display.getImageIO() to get an instance
of this class.
Fields
public static final String FORMAT_JPEG = "jpeg" | Indicates the JPEG output format |
public static final String FORMAT_PNG = "png" | Indicates the PNG output format |
Constructors
public ImageIO() |
Methods
Inherited methods
Field details
FORMAT_JPEG
public static final String FORMAT_JPEG = "jpeg"Indicates the JPEG output format
FORMAT_PNG
public static final String FORMAT_PNG = "png"Indicates the PNG output format
Constructor details
ImageIO
public ImageIO()Method details
getImageIO
public static ImageIO getImageIO()Gets the ImageIO instance
Returns
the image IO instance or null if image IO isn’t supported for the
given platform
save
public abstract void save(InputStream image, OutputStream response, String format, int width, int height, float quality)
throws IOExceptionSaves an image file at the given resolution, scaling if necessary
Parameters
imageInputStream- source image stream
responseOutputStream- resulting image output will be written to this stream
formatString- the format for the image either FORMAT_PNG or FORMAT_JPEG
widthint- the width for the resulting image, use -1 to not scale
heightint- the height of the resulting image, use -1 to not scale
qualityfloat- 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.
Throws
save
public void save(Image img, OutputStream response, String format, float quality)
throws IOExceptionSaves an image object to the given format
Parameters
imgImage- the image object
responseOutputStream- resulting image output will be written to this stream
formatString- the format for the image either FORMAT_PNG or FORMAT_JPEG
qualityfloat- 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.
Throws
save
public void save(String imageFilePath, OutputStream response, String format, int width, int height, float quality)
throws IOExceptionSaves an image file at the given resolution, scaling if necessary
Parameters
imageFilePathString- the image file path
responseOutputStream- resulting image output will be written to this stream
formatString- the format for the image either FORMAT_PNG or FORMAT_JPEG
widthint- the width for the resulting image, use -1 to not scale
heightint- the height of the resulting image, use -1 to not scale
qualityfloat- 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.
Throws
getImageSize
public Dimension getImageSize(String imageFilePath)
throws IOExceptionReturns the image size in pixels
Parameters
imageFilePathString- the path to the image
Returns
the size in pixels
Throws
saveAndKeepAspect
public String saveAndKeepAspect(String imageFilePath, String preferredOutputPath, String format, int width, int height, float quality, boolean onlyDownscale, boolean scaleToFill)
throws IOExceptionScales an image on disk while maintaining an aspect ratio, the appropriate aspect size will be
picked based on the status of scaleToFill
Parameters
imageFilePathString- the path to the image
preferredOutputPathString- the url where the image will be saved
formatString- the format for the image either FORMAT_JPEG or FORMAT_PNG
widthint- the desired width, either width or height will be respected based on aspect dimensions
heightint- the desired height, either width or height will be respected based on aspect dimensions
qualityfloat- 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.
onlyDownscaleboolean- will not scale if the resolution to scale will be higher in this case will return the imageFilePath
scaleToFillboolean- 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 height
Returns
the url for the scaled image or the url of the unscaled image
Throws
IOException- if the operation fails
saveImage
protected abstract void saveImage(Image img, OutputStream response, String format, float quality)
throws IOExceptionSaves an image object to the given format
Parameters
imgImage- the image object
responseOutputStream- resulting image output will be written to this stream
formatString- the format for the image either FORMAT_PNG or FORMAT_JPEG
qualityfloat- 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.
Throws
isFormatSupported
public abstract boolean isFormatSupported(String format)Indicates if the given format for output is supported by this implementation
Parameters
formatString- the format for the image either FORMAT_PNG or FORMAT_JPEG
Returns
true if supported