public class XdevImage extends ImageIcon
ImageIcon
.
Provides methods to load, change and write images.
Supported image formats are JPG, GIF, PNG and BMP.
ImageIcon
,
IOUtils
,
Serialized FormImageIcon.AccessibleImageIcon
Constructor and Description |
---|
XdevImage(byte[] data)
Creates an
XdevImage from an array of bytes containing the image
data. |
XdevImage(File file)
|
XdevImage(Image image)
Creates an
XdevImage from an image object. |
XdevImage(InputStream in)
Loads an
XdevImage from an InputStream . |
XdevImage(String path)
Creates an
XdevImage from an path containing the image data. |
XdevImage(URL url)
|
Modifier and Type | Method and Description |
---|---|
Image |
getAWTImage()
Returns this
XdevImage 's Image . |
int |
getImageHeight()
Gets the height of the image.
|
int |
getImageWidth()
Gets the width of the image.
|
void |
scale(int width,
int height)
Scales this image to the given
width and height
. |
void |
write(File file,
String format)
Writes an image using an arbitrary
ImageWriter that supports the
given format to a File . |
void |
write(File file,
String format,
double quality)
Writes an image using an arbitrary
ImageWriter that supports the
given format to a File . |
void |
write(OutputStream out,
String format)
Writes an image using an arbitrary
ImageWriter that supports the
given format to an OutputStream . |
void |
write(OutputStream out,
String format,
double quality)
Writes an image using an arbitrary
ImageWriter that supports the
given format to an OutputStream . |
getAccessibleContext, getDescription, getIconHeight, getIconWidth, getImage, getImageLoadStatus, getImageObserver, loadImage, paintIcon, setDescription, setImage, setImageObserver, toString
public XdevImage(Image image)
XdevImage
from an image object. If the image has a
"comment" property that is a string, then the string is used as the
description of this image.image
- the imageImage.getProperty(String, java.awt.image.ImageObserver)
,
ImageIcon.getDescription()
public XdevImage(InputStream in) throws IOException
XdevImage
from an InputStream
.in
- an InputStream
to read fromIOException
- if an error occurs during readingpublic XdevImage(File file) throws IOException
file
- a File
to read fromIOException
- if an error occurs during readingpublic XdevImage(URL url) throws IOException
url
- a URL
to read fromIOException
- if an error occurs during readingpublic XdevImage(byte[] data) throws IOException
XdevImage
from an array of bytes containing the image
data.data
- the image data as an array of bytesIOException
- if an error occurs while creating the imagepublic XdevImage(String path) throws IOException
XdevImage
from an path containing the image data.path
- the relative path of the image, e.g. 'res/image/splash.png'IOException
- if an error occurs while creating the imagepublic int getImageWidth()
public int getImageHeight()
public void scale(int width, int height)
width
and height
.
If either width
or height
is a negative number
then a value is substituted to maintain the aspect ratio of the original
image dimensions. If both width
and height
are
negative, then the original image dimensions are used.
width
- the width to which to scale the image.height
- the height to which to scale the image.public Image getAWTImage()
XdevImage
's Image
.Image
object for this XdevImage
public void write(OutputStream out, String format) throws IOException, IllegalArgumentException
ImageWriter
that supports the
given format to an OutputStream
.
This method does not close the provided OutputStream
after the
write operation has completed; it is the responsibility of the caller to
close the stream, if desired.
out
- the OutputStream
to be written toformat
- the informal name of the formatIOException
- if an error occurs during writingIllegalArgumentException
- if format is not supportedImageFileFilter.getSupportedImageExtensions()
,
ImageFileFilter.checkImageFormat(String)
public void write(OutputStream out, String format, double quality) throws IOException, IllegalArgumentException
ImageWriter
that supports the
given format to an OutputStream
.
This method does not close the provided OutputStream
after the
write operation has completed; it is the responsibility of the caller to
close the stream, if desired.
If the format doesn't support compression the parameter
quality
has no effect.
Quality guidelines:
out
- the OutputStream
to be written toformat
- the informal name of the formatquality
- compression quality from 0.0 (low) to 1.0 (high)IOException
- if an error occurs during writingIllegalArgumentException
- if format is not supported or quality is not between 0.0 and
1.0, inclusiveImageFileFilter.getSupportedImageExtensions()
,
ImageFileFilter.checkImageFormat(String)
public void write(File file, String format) throws IOException, IllegalArgumentException
ImageWriter
that supports the
given format to a File
. If there is already a File
present, its contents are discarded.file
- the File
to be written toformat
- the informal name of the formatIOException
- if an error occurs during writingIllegalArgumentException
- if format is not supportedImageFileFilter.getSupportedImageExtensions()
,
ImageFileFilter.checkImageFormat(String)
public void write(File file, String format, double quality) throws IOException, IllegalArgumentException
ImageWriter
that supports the
given format to a File
.
If the format doesn't support compression the parameter
quality
has no effect.
Quality guidelines:
file
- the File
to be written toformat
- the informal name of the formatquality
- compression quality from 0.0 (low) to 1.0 (high)IOException
- if an error occurs during writingIllegalArgumentException
- if format is not supported or quality is not between 0.0 and
1.0, inclusiveImageFileFilter.getSupportedImageExtensions()
,
ImageFileFilter.checkImageFormat(String)
Copyright © 2003–2021 XDEV Software. All rights reserved.