APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.imageio.plugins.bmp

public Class BMPImageWriter

extends ImageWriter
implements BMPConstants
Class Inheritance
All Implemented Interfaces
com.sun.imageio.plugins.bmp.BMPConstants
Imports
java.awt.Rectangle, java.awt.image.ColorModel, .ComponentSampleModel, .DataBuffer, .DataBufferByte, .DataBufferInt, .DataBufferShort, .DataBufferUShort, .DirectColorModel, .IndexColorModel, .MultiPixelPackedSampleModel, .BandedSampleModel, .Raster, .RenderedImage, .SampleModel, .SinglePixelPackedSampleModel, .BufferedImage, java.io.IOException, .ByteArrayOutputStream, java.nio.ByteOrder, java.util.Iterator, javax.imageio.IIOImage, .ImageIO, .ImageTypeSpecifier, .ImageWriteParam, .ImageWriter, javax.imageio.metadata.IIOMetadata, javax.imageio.spi.ImageWriterSpi, javax.imageio.stream.ImageOutputStream, javax.imageio.event.IIOWriteProgressListener, .IIOWriteWarningListener, javax.imageio.plugins.bmp.BMPImageWriteParam, com.sun.imageio.plugins.common.ImageUtil, .I18N

The Java Image IO plugin writer for encoding a binary RenderedImage into a BMP format. The encoding process may clip, subsample using the parameters specified in the ImageWriteParam.
See Also
javax.imageio.plugins.bmp.BMPImageWriteParam

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private int[]
private int[]
private byte[]
private int
private int
private ByteArrayOutputStream
private int
h

private int[]
private boolean
private short[]
private ImageOutputStream
stream

The output stream to write into

private int
private int
w

Inherited from javax.imageio.ImageWriter:
availableLocaleslocaleoriginatingProvideroutputprogressListenerswarningListenerswarningLocales

Constructor Summary

AccessConstructor and Description
public
BMPImageWriter(ImageWriterSpi originator)

Constructs BMPImageWriter based on the provided ImageWriterSpi.

Method Summary

Modifier and TypeMethod and Description
protected boolean
canEncodeImage(int compression, ColorModel cm, SampleModel sm)

protected boolean
canEncodeImage(int compression, ImageTypeSpecifier imgType)

public boolean
canWriteRasters()

Overrides javax.imageio.ImageWriter.canWriteRasters.

Returns true if the methods that take an IIOImage parameter are capable of dealing with a Raster (as opposed to RenderedImage) source image.

public IIOMetadata
convertImageMetadata(IIOMetadata metadata, ImageTypeSpecifier type, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.convertImageMetadata.

Implements javax.imageio.ImageTranscoder.convertImageMetadata.

Returns an IIOMetadata object that may be used for encoding and optionally modified using its document interfaces or other interfaces specific to the writer plug-in that will be used for encoding.

public IIOMetadata
convertStreamMetadata(IIOMetadata inData, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.convertStreamMetadata.

Implements javax.imageio.ImageTranscoder.convertStreamMetadata.

Returns an IIOMetadata object that may be used for encoding and optionally modified using its document interfaces or other interfaces specific to the writer plug-in that will be used for encoding.

private void
encodeRLE4(byte[] bipixels, int scanlineBytes)

private void
encodeRLE8(byte[] bpixels, int scanlineBytes)

private int
firstLowBit(int num)

public IIOMetadata
getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.getDefaultImageMetadata.

Returns an IIOMetadata object containing default values for encoding an image of the given type.

public IIOMetadata
getDefaultStreamMetadata(ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.getDefaultStreamMetadata.

Returns an IIOMetadata object containing default values for encoding a stream of images.

public ImageWriteParam
getDefaultWriteParam()

Overrides javax.imageio.ImageWriter.getDefaultWriteParam.

Returns a new ImageWriteParam object of the appropriate type for this file format containing default values, that is, those values that would be used if no ImageWriteParam object were specified.

protected int
protected int
private synchronized void
incCompImageSize(int value)

private boolean
isEven(int number)

public void
reset()

Overrides javax.imageio.ImageWriter.reset.

Restores the ImageWriter to its initial state.

private int
roundBpp(int x)

public void
setOutput(Object output)

Overrides javax.imageio.ImageWriter.setOutput.

Sets the destination to the given ImageOutputStream or other Object.

public void
write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.write.

Appends a complete image stream containing a single image and associated stream and image metadata and thumbnails to the output.

private void
private void
writeFileHeader(int fileSize, int offset)

private void
writeInfoHeader(int headerSize, int bitsPerPixel)

protected void
writeMaskToPalette(int mask, int i, byte[] r, byte[] g, byte[] b, byte[] a)

private void
writePixels(int l, int scanlineBytes, int bitsPerPixel, int[] pixels, int padding, int numBands, IndexColorModel icm)

private void
writeSize(int dword, int offset)

Inherited from javax.imageio.ImageWriter:
abortabortRequestedaddIIOWriteProgressListeneraddIIOWriteWarningListenercanInsertEmptycanInsertImagecanRemoveImagecanReplaceImageMetadatacanReplacePixelscanReplaceStreamMetadatacanWriteEmptycanWriteSequenceclearAbortRequestdisposeendInsertEmptyendReplacePixelsendWriteEmptyendWriteSequencegetAvailableLocalesgetLocalegetNumThumbnailsSupportedgetOriginatingProvidergetOutputgetPreferredThumbnailSizesprepareInsertEmptyprepareReplacePixelsprepareWriteEmptyprepareWriteSequenceprocessImageCompleteprocessImageProgressprocessImageStartedprocessThumbnailCompleteprocessThumbnailProgressprocessThumbnailStartedprocessWarningOccurredprocessWarningOccurredprocessWriteAbortedremoveAllIIOWriteProgressListenersremoveAllIIOWriteWarningListenersremoveIIOWriteProgressListenerremoveIIOWriteWarningListenerremoveImagereplaceImageMetadatareplacePixelsreplacePixelsreplaceStreamMetadatasetLocalewritewritewriteInsertwriteToSequence

Field Detail

bitMasksback to summary
private int[] bitMasks
bitPosback to summary
private int[] bitPos
bpixelsback to summary
private byte[] bpixels
compImageSizeback to summary
private int compImageSize
compressionTypeback to summary
private int compressionType
embedded_streamback to summary
private ByteArrayOutputStream embedded_stream
hback to summary
private int h
ipixelsback to summary
private int[] ipixels
isTopDownback to summary
private boolean isTopDown
spixelsback to summary
private short[] spixels
streamback to summary
private ImageOutputStream stream

The output stream to write into

versionback to summary
private int version
wback to summary
private int w

Constructor Detail

BMPImageWriterback to summary
public BMPImageWriter(ImageWriterSpi originator)

Constructs BMPImageWriter based on the provided ImageWriterSpi.

Method Detail

canEncodeImageback to summary
protected boolean canEncodeImage(int compression, ColorModel cm, SampleModel sm)
canEncodeImageback to summary
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType)
canWriteRastersback to summary
public boolean canWriteRasters()

Overrides javax.imageio.ImageWriter.canWriteRasters.

Doc from javax.imageio.ImageWriter.canWriteRasters.

Returns true if the methods that take an IIOImage parameter are capable of dealing with a Raster (as opposed to RenderedImage) source image. If this method returns false, then those methods will throw an UnsupportedOperationException if supplied with an IIOImage containing a Raster.

The default implementation returns false.

Annotations
@Override
convertImageMetadataback to summary
public IIOMetadata convertImageMetadata(IIOMetadata metadata, ImageTypeSpecifier type, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.convertImageMetadata.

Implements javax.imageio.ImageTranscoder.convertImageMetadata.

Doc from javax.imageio.ImageTranscoder.convertImageMetadata.

Returns an IIOMetadata object that may be used for encoding and optionally modified using its document interfaces or other interfaces specific to the writer plug-in that will be used for encoding.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the image metadata.

If the supplied ImageWriteParam contains optional setting values not understood by this writer or transcoder, they will be ignored.

Annotations
@Override
convertStreamMetadataback to summary
public IIOMetadata convertStreamMetadata(IIOMetadata inData, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.convertStreamMetadata.

Implements javax.imageio.ImageTranscoder.convertStreamMetadata.

Doc from javax.imageio.ImageTranscoder.convertStreamMetadata.

Returns an IIOMetadata object that may be used for encoding and optionally modified using its document interfaces or other interfaces specific to the writer plug-in that will be used for encoding.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the stream metadata.

If the supplied ImageWriteParam contains optional setting values not understood by this writer or transcoder, they will be ignored.

Annotations
@Override
encodeRLE4back to summary
private void encodeRLE4(byte[] bipixels, int scanlineBytes) throws IOException
encodeRLE8back to summary
private void encodeRLE8(byte[] bpixels, int scanlineBytes) throws IOException
firstLowBitback to summary
private int firstLowBit(int num)
getDefaultImageMetadataback to summary
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.getDefaultImageMetadata.

Doc from javax.imageio.ImageWriter.getDefaultImageMetadata.

Returns an IIOMetadata object containing default values for encoding an image of the given type. The contents of the object may be manipulated using either the XML tree structure returned by the IIOMetadata.getAsTree method, an IIOMetadataController object, or via plug-in specific interfaces, and the resulting data supplied to one of the write methods that take a stream metadata parameter.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the image metadata.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

Annotations
@Override
getDefaultStreamMetadataback to summary
public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param)

Implements abstract javax.imageio.ImageWriter.getDefaultStreamMetadata.

Doc from javax.imageio.ImageWriter.getDefaultStreamMetadata.

Returns an IIOMetadata object containing default values for encoding a stream of images. The contents of the object may be manipulated using either the XML tree structure returned by the IIOMetadata.getAsTree method, an IIOMetadataController object, or via plug-in specific interfaces, and the resulting data supplied to one of the write methods that take a stream metadata parameter.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the stream metadata.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

Writers that do not make use of stream metadata (e.g., writers for single-image formats) should return null.

Annotations
@Override
getDefaultWriteParamback to summary
public ImageWriteParam getDefaultWriteParam()

Overrides javax.imageio.ImageWriter.getDefaultWriteParam.

Doc from javax.imageio.ImageWriter.getDefaultWriteParam.

Returns a new ImageWriteParam object of the appropriate type for this file format containing default values, that is, those values that would be used if no ImageWriteParam object were specified. This is useful as a starting point for tweaking just a few parameters and otherwise leaving the default settings alone.

The default implementation constructs and returns a new ImageWriteParam object that does not allow tiling, progressive encoding, or compression, and that will be localized for the current Locale (i.e., what you would get by calling new ImageWriteParam(getLocale()).

Individual plug-ins may return an instance of ImageWriteParam with additional optional features enabled, or they may return an instance of a plug-in specific subclass of ImageWriteParam.

Annotations
@Override
getPreferredCompressionTypeback to summary
protected int getPreferredCompressionType(ColorModel cm, SampleModel sm)
getPreferredCompressionTypeback to summary
protected int getPreferredCompressionType(ImageTypeSpecifier imageType)
incCompImageSizeback to summary
private synchronized void incCompImageSize(int value)
isEvenback to summary
private boolean isEven(int number)
resetback to summary
public void reset()

Overrides javax.imageio.ImageWriter.reset.

Doc from javax.imageio.ImageWriter.reset.

Restores the ImageWriter to its initial state.

The default implementation calls setOutput(null), setLocale(null), removeAllIIOWriteWarningListeners(), removeAllIIOWriteProgressListeners(), and clearAbortRequest.

Annotations
@Override
roundBppback to summary
private int roundBpp(int x)
setOutputback to summary
public void setOutput(Object output)

Overrides javax.imageio.ImageWriter.setOutput.

Doc from javax.imageio.ImageWriter.setOutput.

Sets the destination to the given ImageOutputStream or other Object. The destination is assumed to be ready to accept data, and will not be closed at the end of each write. This allows distributed imaging applications to transmit a series of images over a single network connection. If output is null, any currently set output will be removed.

If output is an ImageOutputStream, calls to the write, writeToSequence, and prepareWriteEmpty/endWriteEmpty methods will preserve the existing contents of the stream. Other write methods, such as writeInsert, replaceStreamMetadata, replaceImageMetadata, replacePixels, prepareInsertEmpty/endInsertEmpty, and endWriteSequence, require the full contents of the stream to be readable and writable, and may alter any portion of the stream.

Use of a general Object other than an ImageOutputStream is intended for writers that interact directly with an output device or imaging protocol. The set of legal classes is advertised by the writer's service provider's getOutputTypes method; most writers will return a single-element array containing only ImageOutputStream.class to indicate that they accept only an ImageOutputStream.

The default implementation sets the output instance variable to the value of output after checking output against the set of classes advertised by the originating provider, if there is one.

Annotations
@Override
writeback to summary
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException

Implements abstract javax.imageio.ImageWriter.write.

Doc from javax.imageio.ImageWriter.write.

Appends a complete image stream containing a single image and associated stream and image metadata and thumbnails to the output. Any necessary header information is included. If the output is an ImageOutputStream, its existing contents prior to the current seek position are not affected, and need not be readable or writable.

The output must have been set beforehand using the setOutput method.

Stream metadata may optionally be supplied; if it is null, default stream metadata will be used.

If canWriteRasters returns true, the IIOImage may contain a Raster source. Otherwise, it must contain a RenderedImage source.

The supplied thumbnails will be resized if needed, and any thumbnails in excess of the supported number will be ignored. If the format requires additional thumbnails that are not provided, the writer should generate them internally.

An ImageWriteParam may optionally be supplied to control the writing process. If param is null, a default write param will be used.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

Annotations
@Override
Exceptions
IOException:
if an error occurs during writing.
writeEmbeddedback to summary
private void writeEmbedded(IIOImage image, ImageWriteParam bmpParam) throws IOException
writeFileHeaderback to summary
private void writeFileHeader(int fileSize, int offset) throws IOException
writeInfoHeaderback to summary
private void writeInfoHeader(int headerSize, int bitsPerPixel) throws IOException
writeMaskToPaletteback to summary
protected void writeMaskToPalette(int mask, int i, byte[] r, byte[] g, byte[] b, byte[] a)
writePixelsback to summary
private void writePixels(int l, int scanlineBytes, int bitsPerPixel, int[] pixels, int padding, int numBands, IndexColorModel icm) throws IOException
writeSizeback to summary
private void writeSize(int dword, int offset) throws IOException
com.sun.imageio.plugins.bmp back to summary

private Class BMPImageWriter.IIOWriteProgressAdapter

extends Object
implements IIOWriteProgressListener
Class Inheritance
  • java.lang.Object
  • com.sun.imageio.plugins.bmp.BMPImageWriter.IIOWriteProgressAdapter
All Implemented Interfaces
javax.imageio.event.IIOWriteProgressListener, java.util.EventListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
imageComplete(ImageWriter source)

Implements javax.imageio.event.IIOWriteProgressListener.imageComplete.

Reports that the image write operation has completed.

public void
imageProgress(ImageWriter source, float percentageDone)

Implements javax.imageio.event.IIOWriteProgressListener.imageProgress.

Reports the approximate degree of completion of the current write call within the associated ImageWriter.

public void
imageStarted(ImageWriter source, int imageIndex)

Implements javax.imageio.event.IIOWriteProgressListener.imageStarted.

Reports that an image write operation is beginning.

public void
thumbnailComplete(ImageWriter source)

Implements javax.imageio.event.IIOWriteProgressListener.thumbnailComplete.

Reports that a thumbnail write operation has completed.

public void
thumbnailProgress(ImageWriter source, float percentageDone)

Implements javax.imageio.event.IIOWriteProgressListener.thumbnailProgress.

Reports the approximate degree of completion of the current thumbnail write within the associated ImageWriter.

public void
thumbnailStarted(ImageWriter source, int imageIndex, int thumbnailIndex)

Implements javax.imageio.event.IIOWriteProgressListener.thumbnailStarted.

Reports that a thumbnail write operation is beginning.

public void
writeAborted(ImageWriter source)

Implements javax.imageio.event.IIOWriteProgressListener.writeAborted.

Reports that a write has been aborted via the writer's abort method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IIOWriteProgressAdapterback to summary
private IIOWriteProgressAdapter()

Method Detail

imageCompleteback to summary
public void imageComplete(ImageWriter source)

Implements javax.imageio.event.IIOWriteProgressListener.imageComplete.

Doc from javax.imageio.event.IIOWriteProgressListener.imageComplete.

Reports that the image write operation has completed. All ImageWriter implementations are required to call this method exactly once upon completion of each image write operation.

Annotations
@Override
imageProgressback to summary
public void imageProgress(ImageWriter source, float percentageDone)

Implements javax.imageio.event.IIOWriteProgressListener.imageProgress.

Doc from javax.imageio.event.IIOWriteProgressListener.imageProgress.

Reports the approximate degree of completion of the current write call within the associated ImageWriter.

The degree of completion is expressed as an index indicating which image is being written, and a percentage varying from 0.0F to 100.0F indicating how much of the current image has been output. The percentage should ideally be calculated in terms of the remaining time to completion, but it is usually more practical to use a more well-defined metric such as pixels decoded or portion of input stream consumed. In any case, a sequence of calls to this method during a given read operation should supply a monotonically increasing sequence of percentage values. It is not necessary to supply the exact values 0 and 100, as these may be inferred by the callee from other methods.

Each particular ImageWriter implementation may call this method at whatever frequency it desires. A rule of thumb is to call it around each 5 percent mark.

Annotations
@Override
imageStartedback to summary
public void imageStarted(ImageWriter source, int imageIndex)

Implements javax.imageio.event.IIOWriteProgressListener.imageStarted.

Doc from javax.imageio.event.IIOWriteProgressListener.imageStarted.

Reports that an image write operation is beginning. All ImageWriter implementations are required to call this method exactly once when beginning an image write operation.

Annotations
@Override
thumbnailCompleteback to summary
public void thumbnailComplete(ImageWriter source)

Implements javax.imageio.event.IIOWriteProgressListener.thumbnailComplete.

Doc from javax.imageio.event.IIOWriteProgressListener.thumbnailComplete.

Reports that a thumbnail write operation has completed. All ImageWriter implementations are required to call this method exactly once upon completion of each thumbnail write operation.

Annotations
@Override
thumbnailProgressback to summary
public void thumbnailProgress(ImageWriter source, float percentageDone)

Implements javax.imageio.event.IIOWriteProgressListener.thumbnailProgress.

Doc from javax.imageio.event.IIOWriteProgressListener.thumbnailProgress.

Reports the approximate degree of completion of the current thumbnail write within the associated ImageWriter. The semantics are identical to those of imageProgress.

Annotations
@Override
thumbnailStartedback to summary
public void thumbnailStarted(ImageWriter source, int imageIndex, int thumbnailIndex)

Implements javax.imageio.event.IIOWriteProgressListener.thumbnailStarted.

Doc from javax.imageio.event.IIOWriteProgressListener.thumbnailStarted.

Reports that a thumbnail write operation is beginning. All ImageWriter implementations are required to call this method exactly once when beginning a thumbnail write operation.

Annotations
@Override
writeAbortedback to summary
public void writeAborted(ImageWriter source)

Implements javax.imageio.event.IIOWriteProgressListener.writeAborted.

Doc from javax.imageio.event.IIOWriteProgressListener.writeAborted.

Reports that a write has been aborted via the writer's abort method. No further notifications will be given.

Annotations
@Override