Package com.xinapse.image
Class ImageWriter
java.lang.Object
com.xinapse.image.ImageWriter
Contains static methods for writing images.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
userSelectImageFileName
(String fileName, String suggestedFileName, Class<? extends WritableImage> outputImageClass, Component parentComponent) Get the user to select an image file name and, if it is for a UNC image, make sure that the image can be written.static String
write
(ReadableImage image, String fileName, Class<? extends WritableImage> outputImageClass, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom) Writes an image to a disk file with the given file name, possibly changing the Class of the written image.static String
write
(ReadableImage image, String fileName, Class<? extends WritableImage> outputImageClass, PixelDataType saveStoredPixelDataType, ComplexMode complexMode, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom, Component parentComponent, byte[] roiOutput) Writes aReadableImage
to a specfied class ofWritableImage
, possibly changing the pixel data type.static String
write
(WritableImage image, String fileName, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom) Writes an image to a disk file with the given file name.static String
write
(WritableImage image, String fileName, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom, Component parentComponent) Writes an image to a disk file with the given file name.
-
Method Details
-
write
public static String write(WritableImage image, String fileName, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom) throws InvalidImageException, IOException, CancelledException Writes an image to a disk file with the given file name.- Parameters:
image
- the image to write.fileName
- the file name to which to write the image. In some cases this may act as the base file name (for example when writing Analyze images).requireMandatoryDICOMElements
- if the image is a DICOM image, this controls whether mandatory DICOM elements are required, and if not present an error should occur.oneFilePerSliceDicom
- true if DICOM images are to be written one-file-per-slice.- Returns:
- the file name to which the images was actually written
- Throws:
InvalidImageException
- if the image to be written is invalid.IOException
- in an I/O error occurs during the write operation.CancelledException
- if the write operation is cancelled by the user.
-
write
public static String write(ReadableImage image, String fileName, Class<? extends WritableImage> outputImageClass, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom) throws InvalidImageException, IOException, CancelledException Writes an image to a disk file with the given file name, possibly changing the Class of the written image.- Parameters:
image
- the image to write.fileName
- the file name to which to write the image. In some cases this may act as the base file name (for example when writing Analyze images).outputImageClass
- the Class of image to be written.requireMandatoryDICOMElements
- if the image is a DICOM image, this controls whether mandatory DICOM elements are required, and if not present an error should occur.oneFilePerSliceDicom
- true if DICOM images are to be written one-file-per-slice.- Returns:
- the file name to which the images was actually written
- Throws:
InvalidImageException
- if the image to be written is invalid.IOException
- in an I/O error occurs during the write operation.CancelledException
- if the write operation is cancelled by the user.
-
write
public static String write(WritableImage image, String fileName, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom, Component parentComponent) throws InvalidImageException, IOException, CancelledException Writes an image to a disk file with the given file name.- Parameters:
image
- the image to write.fileName
- the name of the disk file to which the image will be saved. In some cases, this may act as the base file name (for example when writing Analyze images). If null, the user will be prompted to select a file name for output.requireMandatoryDICOMElements
- if the output image is a DICOM image, this controls whether mandatory DICOM elements are required, and if not present an error should occur.oneFilePerSliceDicom
- true if DICOM images are to be written one-file-per-slice.parentComponent
- the Component that will be used to position any dialogs used to prompt for user input that may be required when prompting for mandatory DICOM elements.- Returns:
- the file name to which the image was actually written
- Throws:
InvalidImageException
- if the image to be written is invalid.IOException
- in an I/O error occurs during the write operation.CancelledException
- if the write operation is cancelled by the user.
-
write
public static String write(ReadableImage image, String fileName, Class<? extends WritableImage> outputImageClass, PixelDataType saveStoredPixelDataType, ComplexMode complexMode, boolean requireMandatoryDICOMElements, boolean oneFilePerSliceDicom, Component parentComponent, byte[] roiOutput) throws InvalidImageException, IOException, CancelledException Writes aReadableImage
to a specfied class ofWritableImage
, possibly changing the pixel data type.- Parameters:
image
- the image to write.fileName
- the name of the disk file to which the image will be saved. In some cases, this may act as the base file name (for example when writing Analyze images). If null, the user will be prompted to select a file name for output.outputImageClass
- the class of WritableImage to which the image will be written.saveStoredPixelDataType
- thePixelDataType
with which the image will be saved on disk.complexMode
- theComplexMode
if this is a Complex image, and thesavePixelDataType
is not complex.requireMandatoryDICOMElements
- if the output image is a DICOM image, this controls whether mandatory DICOM elements are required, and if not present an error should occur.oneFilePerSliceDicom
- true if DICOM images are to be written one-file-per-slice.parentComponent
- if non-null
, aComponent
used when positioning pop-up message dialogs.roiOutput
- for DICOM images, the text describing the ROIs, to be saved in a DICOM Element.- Returns:
- the file name with which the image was actually written.
- Throws:
InvalidImageException
- if the image cannot be created.IOException
- if an I/O error occurs during the save to disk.CancelledException
- if the save operation is cancelled.
-
userSelectImageFileName
public static String userSelectImageFileName(String fileName, String suggestedFileName, Class<? extends WritableImage> outputImageClass, Component parentComponent) throws IOException, CancelledException Get the user to select an image file name and, if it is for a UNC image, make sure that the image can be written.- Parameters:
fileName
- ifnull
, the user is prompted for a file name. If non-null, this file name is returned.suggestedFileName
- if the user is prompted for a file name. then this is the default file name set in the image chooser dialog.outputImageClass
- the class of the output image.parentComponent
- if non-null, the component used to position the pop-up dialogs.- Returns:
- the name of the user-selected image file.
- Throws:
IOException
- if the outputImageClass is UNCImage.class, and the image cannot be written.CancelledException
- if file selection is cancelled by the user.
-