org.dcm4che2.imageioimpl.plugins.dcm
Class DicomImageWriter

java.lang.Object
  extended by javax.imageio.ImageWriter
      extended by org.dcm4che2.imageioimpl.plugins.dcm.DicomImageWriter
All Implemented Interfaces:
javax.imageio.ImageTranscoder

public class DicomImageWriter
extends javax.imageio.ImageWriter

Write DICOM files containing images - handles transcoding to a new representation, as well as transcoding the images. Can also use raw data if the original type is the same type as the new one.

Author:
bwallace

Field Summary
protected  DicomOutputStream dos
           
protected  boolean encapsulated
           
protected  javax.imageio.ImageWriteParam writeParam
          The write param for the child element
protected  javax.imageio.ImageWriter writer
           
 
Fields inherited from class javax.imageio.ImageWriter
availableLocales, locale, originatingProvider, output, progressListeners, warningListeners, warningLocales
 
Constructor Summary
DicomImageWriter(javax.imageio.spi.ImageWriterSpi spi)
          Create a new DICOM Image Writer.
 
Method Summary
 boolean canWriteSequence()
          Writing as a sequence is actually the preferred approach.
 javax.imageio.metadata.IIOMetadata convertImageMetadata(javax.imageio.metadata.IIOMetadata metadata, javax.imageio.ImageTypeSpecifier type, javax.imageio.ImageWriteParam param)
          The image metadata provided MUST be of the correct type for the child image writer, as the meta-data will only be written to the child image.
 javax.imageio.metadata.IIOMetadata convertStreamMetadata(javax.imageio.metadata.IIOMetadata metadata, javax.imageio.ImageWriteParam param)
          Can't convert anything except existing DicomStreamMetaData
 void endWriteSequence()
          Finish writing the header data to the stream.
protected  byte[] extractImageEncoding(javax.imageio.IIOImage iioimage, javax.imageio.ImageWriteParam param)
          This method gets the encoded image from the given object as a byte array of data.
 javax.imageio.metadata.IIOMetadata getDefaultImageMetadata(javax.imageio.ImageTypeSpecifier image, javax.imageio.ImageWriteParam writeParam)
          No easy way to figure out what htis one as as the stream meta-data isn't yet available.
 javax.imageio.metadata.IIOMetadata getDefaultStreamMetadata(javax.imageio.ImageWriteParam arg0)
          Get a default set of DICOM data to use in the stream meta-data.
 void prepareWriteSequence(javax.imageio.metadata.IIOMetadata metadata)
          Start writing the intiial sequence.
protected  void setupWriter(javax.imageio.metadata.IIOMetadata metadata)
          Sets up the child writer if it hasn't already been setup
 void updateDicomHeader(DicomStreamMetaData metadata, java.awt.image.BufferedImage image)
          This updates the metadata with relevant information from the image, such as the size etc.
 void write(javax.imageio.metadata.IIOMetadata metadata, javax.imageio.IIOImage iioimage, javax.imageio.ImageWriteParam param)
          Writes the image, including the DICOM metadata.
 void writeBytesToSequence(byte[] data, javax.imageio.ImageWriteParam param)
          Write the given image as a byte array to the sequence.
 void writeToSequence(javax.imageio.IIOImage iioimage, javax.imageio.ImageWriteParam param)
          Write the given image to the sequence.
 
Methods inherited from class javax.imageio.ImageWriter
abort, abortRequested, addIIOWriteProgressListener, addIIOWriteWarningListener, canInsertEmpty, canInsertImage, canRemoveImage, canReplaceImageMetadata, canReplacePixels, canReplaceStreamMetadata, canWriteEmpty, canWriteRasters, clearAbortRequest, dispose, endInsertEmpty, endReplacePixels, endWriteEmpty, getAvailableLocales, getDefaultWriteParam, getLocale, getNumThumbnailsSupported, getOriginatingProvider, getOutput, getPreferredThumbnailSizes, prepareInsertEmpty, prepareReplacePixels, prepareWriteEmpty, processImageComplete, processImageProgress, processImageStarted, processThumbnailComplete, processThumbnailProgress, processThumbnailStarted, processWarningOccurred, processWarningOccurred, processWriteAborted, removeAllIIOWriteProgressListeners, removeAllIIOWriteWarningListeners, removeIIOWriteProgressListener, removeIIOWriteWarningListener, removeImage, replaceImageMetadata, replacePixels, replacePixels, replaceStreamMetadata, reset, setLocale, setOutput, write, write, writeInsert
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dos

protected DicomOutputStream dos

writer

protected javax.imageio.ImageWriter writer

writeParam

protected javax.imageio.ImageWriteParam writeParam
The write param for the child element


encapsulated

protected boolean encapsulated
Constructor Detail

DicomImageWriter

public DicomImageWriter(javax.imageio.spi.ImageWriterSpi spi)
Create a new DICOM Image Writer.

Method Detail

convertImageMetadata

public javax.imageio.metadata.IIOMetadata convertImageMetadata(javax.imageio.metadata.IIOMetadata metadata,
                                                               javax.imageio.ImageTypeSpecifier type,
                                                               javax.imageio.ImageWriteParam param)
The image metadata provided MUST be of the correct type for the child image writer, as the meta-data will only be written to the child image.

Specified by:
convertImageMetadata in interface javax.imageio.ImageTranscoder
Specified by:
convertImageMetadata in class javax.imageio.ImageWriter

convertStreamMetadata

public javax.imageio.metadata.IIOMetadata convertStreamMetadata(javax.imageio.metadata.IIOMetadata metadata,
                                                                javax.imageio.ImageWriteParam param)
Can't convert anything except existing DicomStreamMetaData

Specified by:
convertStreamMetadata in interface javax.imageio.ImageTranscoder
Specified by:
convertStreamMetadata in class javax.imageio.ImageWriter

getDefaultImageMetadata

public javax.imageio.metadata.IIOMetadata getDefaultImageMetadata(javax.imageio.ImageTypeSpecifier image,
                                                                  javax.imageio.ImageWriteParam writeParam)
No easy way to figure out what htis one as as the stream meta-data isn't yet available. Suggest only using this after starting to write the stream, as at that point, the child writer will be available.

Specified by:
getDefaultImageMetadata in class javax.imageio.ImageWriter

getDefaultStreamMetadata

public javax.imageio.metadata.IIOMetadata getDefaultStreamMetadata(javax.imageio.ImageWriteParam arg0)
Get a default set of DICOM data to use in the stream meta-data.

Specified by:
getDefaultStreamMetadata in class javax.imageio.ImageWriter

updateDicomHeader

public void updateDicomHeader(DicomStreamMetaData metadata,
                              java.awt.image.BufferedImage image)
This updates the metadata with relevant information from the image, such as the size etc.

Parameters:
metadata -
image -

write

public void write(javax.imageio.metadata.IIOMetadata metadata,
                  javax.imageio.IIOImage iioimage,
                  javax.imageio.ImageWriteParam param)
           throws java.io.IOException
Writes the image, including the DICOM metadata.

Specified by:
write in class javax.imageio.ImageWriter
Throws:
java.io.IOException

canWriteSequence

public boolean canWriteSequence()
Writing as a sequence is actually the preferred approach. All the regular write method does is writes to a sequence.

Overrides:
canWriteSequence in class javax.imageio.ImageWriter

setupWriter

protected void setupWriter(javax.imageio.metadata.IIOMetadata metadata)
Sets up the child writer if it hasn't already been setup


prepareWriteSequence

public void prepareWriteSequence(javax.imageio.metadata.IIOMetadata metadata)
                          throws java.io.IOException
Start writing the intiial sequence.

Overrides:
prepareWriteSequence in class javax.imageio.ImageWriter
Throws:
java.io.IOException

writeToSequence

public void writeToSequence(javax.imageio.IIOImage iioimage,
                            javax.imageio.ImageWriteParam param)
                     throws java.io.IOException
Write the given image to the sequence.

Overrides:
writeToSequence in class javax.imageio.ImageWriter
Throws:
java.io.IOException

writeBytesToSequence

public void writeBytesToSequence(byte[] data,
                                 javax.imageio.ImageWriteParam param)
                          throws java.io.IOException
Write the given image as a byte array to the sequence.

Throws:
java.io.IOException

extractImageEncoding

protected byte[] extractImageEncoding(javax.imageio.IIOImage iioimage,
                                      javax.imageio.ImageWriteParam param)
                               throws java.io.IOException
This method gets the encoded image from the given object as a byte array of data.

Throws:
java.io.IOException

endWriteSequence

public void endWriteSequence()
                      throws java.io.IOException
Finish writing the header data to the stream.

Overrides:
endWriteSequence in class javax.imageio.ImageWriter
Throws:
java.io.IOException


Copyright © 2011 dcm4che. All Rights Reserved.