/** Returns an input stream containing the written data */ private ImageInputStream writeImage(DicomStreamMetaData newMeta, BufferedImage bi, String name) throws IOException { File f = new File(name + ".dcm"); if (f.exists()) f.delete(); ImageOutputStream imageOutput = new FileImageOutputStream(f); DicomImageWriter writer = (DicomImageWriter) new DicomImageWriterSpi().createWriterInstance(); IIOImage iioimage = new IIOImage(bi, null, null); writer.setOutput(imageOutput); writer.write(newMeta, iioimage, null); imageOutput.close(); return new FileImageInputStream(f); }
/** Returns an input stream containing the written data */ private ImageInputStream writeImageFrames( DicomStreamMetaData newMeta, List<BufferedImage> bis, String name) throws IOException { File f = new File(name + ".dcm"); if (f.exists()) f.delete(); ImageOutputStream imageOutput = new FileImageOutputStream(f); DicomImageWriter writer = (DicomImageWriter) new DicomImageWriterSpi().createWriterInstance(); writer.setOutput(imageOutput); writer.prepareWriteSequence(newMeta); for (BufferedImage bi : bis) { IIOImage iioimage = new IIOImage(bi, null, null); writer.setOutput(imageOutput); writer.writeToSequence(iioimage, null); } imageOutput.close(); return new FileImageInputStream(f); }