本文整理匯總了Java中javax.imageio.ImageReadParam.getDestinationBands方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageReadParam.getDestinationBands方法的具體用法?Java ImageReadParam.getDestinationBands怎麽用?Java ImageReadParam.getDestinationBands使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.ImageReadParam
的用法示例。
在下文中一共展示了ImageReadParam.getDestinationBands方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepareRead
import javax.imageio.ImageReadParam; //導入方法依賴的package包/類
private void prepareRead(int imageIndex, ImageReadParam param)
throws IOException {
if (stream == null) {
throw new IllegalStateException("Input not set!");
}
// A null ImageReadParam means we use the default
if (param == null) {
param = getDefaultReadParam();
}
this.imageReadParam = param;
seekToImage(imageIndex);
this.tileOrStripWidth = getTileOrStripWidth();
this.tileOrStripHeight = getTileOrStripHeight();
this.planarConfiguration = getPlanarConfiguration();
this.sourceBands = param.getSourceBands();
if (sourceBands == null) {
sourceBands = new int[numBands];
for (int i = 0; i < numBands; i++) {
sourceBands[i] = i;
}
}
// Initialize the destination image
Iterator<ImageTypeSpecifier> imageTypes = getImageTypes(imageIndex);
ImageTypeSpecifier theImageType
= ImageUtil.getDestinationType(param, imageTypes);
int destNumBands = theImageType.getSampleModel().getNumBands();
this.destinationBands = param.getDestinationBands();
if (destinationBands == null) {
destinationBands = new int[destNumBands];
for (int i = 0; i < destNumBands; i++) {
destinationBands[i] = i;
}
}
if (sourceBands.length != destinationBands.length) {
throw new IllegalArgumentException(
"sourceBands.length != destinationBands.length");
}
for (int i = 0; i < sourceBands.length; i++) {
int sb = sourceBands[i];
if (sb < 0 || sb >= numBands) {
throw new IllegalArgumentException(
"Source band out of range!");
}
int db = destinationBands[i];
if (db < 0 || db >= destNumBands) {
throw new IllegalArgumentException(
"Destination band out of range!");
}
}
}
示例2: readRaster
import javax.imageio.ImageReadParam; //導入方法依賴的package包/類
@Override
public Raster readRaster(int imageIndex, ImageReadParam param)
throws IOException {
checkIndex(imageIndex);
Rectangle sourceRegion = new Rectangle();
Rectangle destRegion = new Rectangle();
computeRegions(param, getWidth(imageIndex), getHeight(imageIndex),
null, sourceRegion, destRegion);
// Set everything to default values
int sourceXSubsampling = param != null ? param.getSourceXSubsampling()
: 1;
int sourceYSubsampling = param != null ? param.getSourceYSubsampling()
: 1;
Point destinationOffset = param != null ? param.getDestinationOffset()
: new Point(0, 0);
ImageSubheader subheader;
try {
subheader = record.getImages()[imageIndex].getSubheader();
} catch (NITFException e) {
throw new IOException(ExceptionUtils.getStackTrace(e));
}
// String irep = subheader.getImageRepresentation().getStringData().trim();
String pvType = subheader.getPixelValueType().getStringData().trim();
int nbpp = subheader.getNumBitsPerPixel().getIntData();
int bandCount = subheader.getBandCount();
// make the band offsets array, for the output
int[] bandOffsets;
int[] sourceBands = param != null ? param.getSourceBands() : null;
if (param != null && param.getDestinationBands() != null)
bandOffsets = param.getDestinationBands();
else if (param != null && sourceBands != null) {
bandOffsets = new int[sourceBands.length];
System.arraycopy(sourceBands, 0, bandOffsets, 0, bandOffsets.length);
} else {
// Setup band offsets -- TODO should we really read ALL bands by
// default?
bandOffsets = new int[bandCount];
for (int i = 0; i < bandOffsets.length; i++)
bandOffsets[i] = i;
}
int nBytes = ((nbpp - 1) / 8) + 1;
int bufType;
// byte
if (nBytes == 1) {
bufType = DataBuffer.TYPE_BYTE;
}
// short
else if (nBytes == 2) {
bufType = DataBuffer.TYPE_USHORT;
}
// float
else if (nBytes == 4 && pvType.equals("R")) {
bufType = DataBuffer.TYPE_FLOAT;
}
// double
else if (nBytes == 8 && pvType.equals("R")) {
bufType = DataBuffer.TYPE_DOUBLE;
} else {
throw new NotImplementedException("not yet implemented");
}
WritableRaster ras = ImageIOUtils
.makeGenericPixelInterleavedWritableRaster(destRegion.width,
destRegion.height, bandOffsets.length, bufType);
checkReadParamBandSettings(param, bandCount, ras.getSampleModel()
.getNumBands());
readRaster(imageIndex, sourceRegion, destRegion, sourceXSubsampling,
sourceYSubsampling, bandOffsets, nBytes, destinationOffset, ras);
return ras;
}
示例3: read
import javax.imageio.ImageReadParam; //導入方法依賴的package包/類
@Override
public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
readHeader();
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");
}
示例4: prepareRead
import javax.imageio.ImageReadParam; //導入方法依賴的package包/類
private void prepareRead(int imageIndex, ImageReadParam param)
throws IOException {
if (stream == null) {
throw new IllegalStateException("Input not set!");
}
// A null ImageReadParam means we use the default
if (param == null) {
param = getDefaultReadParam();
}
this.imageReadParam = param;
seekToImage(imageIndex);
this.tileOrStripWidth = getTileOrStripWidth();
this.tileOrStripHeight = getTileOrStripHeight();
this.planarConfiguration = getPlanarConfiguration();
this.sourceBands = param.getSourceBands();
if (sourceBands == null) {
sourceBands = new int[numBands];
for (int i = 0; i < numBands; i++) {
sourceBands[i] = i;
}
}
// Initialize the destination image
Iterator imageTypes = getImageTypes(imageIndex);
ImageTypeSpecifier theImageType =
ImageUtil.getDestinationType(param, imageTypes);
int destNumBands = theImageType.getSampleModel().getNumBands();
this.destinationBands = param.getDestinationBands();
if (destinationBands == null) {
destinationBands = new int[destNumBands];
for (int i = 0; i < destNumBands; i++) {
destinationBands[i] = i;
}
}
if (sourceBands.length != destinationBands.length) {
throw new IllegalArgumentException(
"sourceBands.length != destinationBands.length");
}
for (int i = 0; i < sourceBands.length; i++) {
int sb = sourceBands[i];
if (sb < 0 || sb >= numBands) {
throw new IllegalArgumentException(
"Source band out of range!");
}
int db = destinationBands[i];
if (db < 0 || db >= destNumBands) {
throw new IllegalArgumentException(
"Destination band out of range!");
}
}
}