Posted by
Jeff Brandenburg on
URL: http://imagej.273.s1.nabble.com/using-FileOpener-on-16-bit-grayscale-in-java-app-tp3703115p3703116.html
On Apr 10, 2006, at 5:38 PM, Bill Christens-Barry wrote:
> I have a 16-bit grayscale TIFF that I'd like to open, display, and
> work with in a Java app that imports and draws on various classes in
> ij.jar. I ran into trouble when I tried to use BufferedImage's
> TYPE_USHORT_GRAY to ensure that I can get at the 16-bit data.
>
> So far I haven't been successful and wondered if I might be able to do
> this using ij. A quick look at the ImageJ source and API left me a bit
> confused.
>
> I'm trying to use the FileOpener, FileInfo, ImageReader, and
> ShortProcessor classes to get at the 16-bit sample values of the image
> data. In my toy program to work this out, based on the source from
> FileOpener, the compiler gags with these errors:
>
> Rastic8r.java:45: cannot find symbol
> symbol : method createColorModel(ij.io.FileInfo)
> location: class ExtractRaster
> cm = createColorModel(fi);
I can't explain this, as the createColorModel method is clearly there
in FileOpener. Or is ExtractRaster not based on FileOpener?
> Rastic8r.java:50: cannot find symbol
> symbol : method readPixels(ij.io.FileInfo)
> location: class ij.io.ImageReader
> pixels = ir.readPixels(fi);
It looks like you've skipped a step in this second part:
InputStream is = createInputStream(fi);
if (is==null)
return null;
ImageReader reader = new ImageReader(fi);
pixels = reader.readPixels(is);
is.close();
In other words, ImageReader.readPixels() wants an InputStream, not a
FileInfo. You create the InputStream using FileOpener's
createInputStream() method.
--
-jeffB (Jeff Brandenburg, Duke Center for In-Vivo Microscopy)