Package jahuwaldt.image.encoders
Class JPEGEncoderAdapter
- java.lang.Object
-
- jahuwaldt.image.encoders.JPEGEncoderAdapter
-
- All Implemented Interfaces:
ImageEncoder
public class JPEGEncoderAdapter extends java.lang.Object implements ImageEncoder
Adapter class for the Sun JPEG Encoder.
-
-
Constructor Summary
Constructors Constructor Description JPEGEncoderAdapter()
Creates a newJPEGEncoderAdapter
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
encode(java.awt.image.BufferedImage bufferedImage)
Encodes an image in JPEG format.void
encode(java.awt.image.BufferedImage bufferedImage, java.io.OutputStream outputStream)
Encodes an image in JPEG format and writes it to an output stream.float
getQuality()
Returns the quality of the image encoding, which is a number in the range 0.0f to 1.0f (higher values give better quality output, but larger file sizes).boolean
isEncodingAlpha()
Returnsfalse
always, indicating that this encoder does not encode alpha transparency.void
setEncodingAlpha(boolean encodingAlpha)
Set whether the encoder should encode alpha transparency (this is not supported for JPEG, so this method does nothing).void
setQuality(float quality)
Set the quality of the image encoding.
-
-
-
Constructor Detail
-
JPEGEncoderAdapter
public JPEGEncoderAdapter()
Creates a newJPEGEncoderAdapter
instance.
-
-
Method Detail
-
getQuality
public float getQuality()
Returns the quality of the image encoding, which is a number in the range 0.0f to 1.0f (higher values give better quality output, but larger file sizes). The default value is 0.95f.- Specified by:
getQuality
in interfaceImageEncoder
- Returns:
- A float representing the quality, in the range 0.0f to 1.0f.
- See Also:
setQuality(float)
-
setQuality
public void setQuality(float quality)
Set the quality of the image encoding.- Specified by:
setQuality
in interfaceImageEncoder
- Parameters:
quality
- A float representing the quality (in the range 0.0f to 1.0f).- See Also:
getQuality()
-
isEncodingAlpha
public boolean isEncodingAlpha()
Returnsfalse
always, indicating that this encoder does not encode alpha transparency.- Specified by:
isEncodingAlpha
in interfaceImageEncoder
- Returns:
false
.
-
setEncodingAlpha
public void setEncodingAlpha(boolean encodingAlpha)
Set whether the encoder should encode alpha transparency (this is not supported for JPEG, so this method does nothing).- Specified by:
setEncodingAlpha
in interfaceImageEncoder
- Parameters:
encodingAlpha
- ignored.
-
encode
public byte[] encode(java.awt.image.BufferedImage bufferedImage) throws java.io.IOException
Encodes an image in JPEG format.- Specified by:
encode
in interfaceImageEncoder
- Parameters:
bufferedImage
- the image to be encoded (null
not permitted).- Returns:
- The byte[] that is the encoded image.
- Throws:
java.io.IOException
- if there is an I/O problem.java.lang.NullPointerException
- ifbufferedImage
isnull
.
-
encode
public void encode(java.awt.image.BufferedImage bufferedImage, java.io.OutputStream outputStream) throws java.io.IOException
Encodes an image in JPEG format and writes it to an output stream.- Specified by:
encode
in interfaceImageEncoder
- Parameters:
bufferedImage
- the image to be encoded (null
not permitted).outputStream
- the OutputStream to write the encoded image to (null
not permitted).- Throws:
java.io.IOException
- if there is an I/O problem.java.lang.NullPointerException
- ifbufferedImage
isnull
.
-
-