List of usage examples for javax.imageio ImageTypeSpecifier getNumBands
public int getNumBands()
From source file:nitf.imageio.NITFReader.java
@Override public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException { readHeader();/*from ww w. jav a 2 s .c om*/ Raster raster = readRaster(imageIndex, param); // get the requested number of destination bands (or 0 for all) int numDestBands = param != null ? (param.getDestinationBands() != null ? param.getDestinationBands().length : param.getSourceBands() != null ? param.getSourceBands().length : 0) : 0; // try to find a good match for the specifier ImageTypeSpecifier imageType = null, firstType = null; Iterator<ImageTypeSpecifier> imageTypes = getImageTypes(imageIndex); while (imageTypes.hasNext() && imageType == null) { ImageTypeSpecifier currentImageType = imageTypes.next(); if (firstType == null) firstType = currentImageType; if (currentImageType.getNumBands() == numDestBands) imageType = currentImageType; } if (imageType == null) { if (firstType == null) throw new IOException("Unable to determine the ImageTypeSpecifier"); else imageType = firstType; } try { ImageSubheader subheader = record.getImages()[imageIndex].getSubheader(); String pvType = subheader.getPixelValueType().getStringData().trim(); int nbpp = subheader.getNumBitsPerPixel().getIntData(); int nBytes = ((nbpp - 1) / 8) + 1; if (nBytes == 1 || nBytes == 2 || (nBytes == 4 && pvType.equals("R")) || (nBytes == 8 && pvType.equals("R"))) { return ImageIOUtils.rasterToBufferedImage(raster, imageType); } } catch (NITFException e) { throw new IOException(ExceptionUtils.getStackTrace(e)); } throw new NotImplementedException("Image pixel type or bits per pixel not yet supported"); }