Re: Open an ImagePlus from a stream or bytearray

Posted by dscho on
URL: http://imagej.273.s1.nabble.com/Open-an-ImagePlus-from-a-stream-or-bytearray-tp3700040p3700043.html

Hi,

On Fri, 16 Mar 2007, Johannes Hermen wrote:

> Does anybody know if it is possible to create an ImagePlus directly from
> an InputStream or a ByteArray.

AFAICT, no. The openImage() method of ij.io.Opener wants to look at the
file type first, which means that it also wants to look at the filename.

> I need to create ImagePlus objects from DICOM files that are retrieved
> from a Database, so that i can only get them as Stream or ByteArray.

That might be easier: you already _know_ that it is a DICOM file. But you
have to hack the class DicomDecoder in ij.plugin.DICOM so that it actually
takes a preinitialised BufferedInputStream instead of opening it itself
(you might do this by wrapping lines 365-369 in an "if (f == null) {...}",
and adding a new constructor which also takes a BufferedInputStream and
initialises "f" with that.

As for the ByteArray: there is java.io.ByteArrayInputStream which wraps
the array in a stream.

AFAICT DICOM.java is self-contained, so to test all this, you can just
copy it somewhere else (but do not forget to adjust the package name! I do
that regulary, and it compiles, but throws an exception...).

Hth,
Dscho