本文整理汇总了Java中javax.imageio.ImageReadParam.setSourceSubsampling方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReadParam.setSourceSubsampling方法的具体用法?Java ImageReadParam.setSourceSubsampling怎么用?Java ImageReadParam.setSourceSubsampling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageReadParam
的用法示例。
在下文中一共展示了ImageReadParam.setSourceSubsampling方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public BufferedImage call() throws Exception {
ImageInputStream iis = null;
try {
LOGGER.debug("Loading {} @ {}", url.toString(), level);
final ImageReader imgReader = ImageIO.getImageReadersBySuffix(suffix(url.getFile())).next();
iis = ImageIO.createImageInputStream(url.openStream());
imgReader.setInput(iis);
final ImageReadParam readParam = imgReader.getDefaultReadParam();
if (level > 0) {
readParam.setSourceSubsampling(level, level, 0, 0);
}
BufferedImage img = imgReader.read(0, readParam);
return img;
} catch (IOException ioe) {
LOGGER.error("Unable to load image", ioe);
return null;
} finally {
if (iis != null) {
try {
iis.close();
} catch (IOException e) {
// ignore
}
}
if (component != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
component.invalidate();
component.validate();
component.repaint();
}
});
}
}
}
示例2: loadSubimage
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public void loadSubimage(ImageInput ii, Rectangle region, int prescale)
throws FileOpException {
logger.debug("loadSubimage: "+ii.getFile());
//System.gc();
try {
if ((reader == null) || (imgFile != ii.getFile())) {
getReader(ii);
}
ImageReadParam readParam = reader.getDefaultReadParam();
readParam.setSourceRegion(region);
readParam.setSourceSubsampling(prescale, prescale, 0, 0);
img = reader.read(0, readParam);
/* JAI imageread seems to ignore the readParam :-(
ImageInputStream istream = (ImageInputStream) reader.getInput();
ParameterBlockJAI pb = new ParameterBlockJAI("imageread");
pb.setParameter("Input", istream);
pb.setParameter("ReadParam", readParam);
pb.setParameter("Reader", reader);
img = JAI.create("imageread", pb);
*/
} catch (IOException e) {
throw new FileOpException("Unable to load File!");
}
if (img == null) {
throw new FileOpException("Unable to load File!");
}
imgFile = ii.getFile();
}
示例3: copyReadParam
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
protected void copyReadParam(ImageReadParam src, ImageReadParam dst) {
dst.setDestination(src.getDestination());
dst.setSourceRegion(src.getSourceRegion());
dst.setSourceSubsampling(src.getSourceXSubsampling(), src
.getSourceYSubsampling(), src.getSubsamplingXOffset(), src
.getSubsamplingYOffset());
dst.setDestinationOffset(src.getDestinationOffset());
if (ImageReaderFactory.getInstance().needsImageTypeSpecifier(tsuid)) {
dst.setDestinationType(createImageTypeSpecifier());
}
}
示例4: readBandData
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public void readBandData(int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight,
int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException {
pm.beginTask("Reading band ...", sourceHeight);
try {
ImageReadParam readParam = reader.getDefaultReadParam();
readParam.setSourceBands(new int[]{0});
readParam.setSourceSubsampling(sourceStepX, sourceStepY, 0, 0);
readParam.setSourceRegion(new Rectangle(sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight));
Raster raster;
synchronized (lock) {
raster = reader.readRaster(0, readParam);
}
DataBuffer dataBuffer = raster.getDataBuffer();
int bufferSize = dataBuffer.getSize();
switch (destBuffer.getType()) {
case ProductData.TYPE_UINT8:
case ProductData.TYPE_INT8:
case ProductData.TYPE_INT32:
for (int i = 0; i < bufferSize; i++) {
if (pm.isCanceled()) {
break;
}
destBuffer.setElemIntAt(i, dataBuffer.getElem(i));
}
break;
case ProductData.TYPE_UINT16:
case ProductData.TYPE_INT16:
for (int i = 0; i < bufferSize; i++) {
if (pm.isCanceled()) {
break;
}
destBuffer.setElemUIntAt(i, swapBytes((short) dataBuffer.getElem(i)));
}
break;
case ProductData.TYPE_UINT32:
for (int i = 0; i < bufferSize; i++) {
if (pm.isCanceled()) {
break;
}
destBuffer.setElemUIntAt(i, dataBuffer.getElem(i));
}
break;
case ProductData.TYPE_FLOAT32:
for (int i = 0; i < bufferSize; i++) {
if (pm.isCanceled()) {
break;
}
destBuffer.setElemFloatAt(i, dataBuffer.getElemFloat(i));
}
break;
}
pm.worked(1);
} catch (IOException e) {
logger.severe(e.getMessage());
throw e;
} finally {
pm.done();
}
}
示例5: readSLCRasterBand
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public static double[] readSLCRasterBand(int x, int y, int width, int height) throws IOException {
final double[] srcArray;
final ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next();
ImageInputStream iis = ImageIO.createImageInputStream(file);
reader.setInput(iis);
final ImageReadParam param = reader.getDefaultReadParam();
param.setSourceSubsampling(width,height,0,0);
final RenderedImage image = reader.readAsRenderedImage(0,param);
final Raster data = image.getData(new Rectangle(0,0, width, height));
final SampleModel sampleModel = data.getSampleModel();
srcArray = new double[width * height];
double[] samples = sampleModel.getSamples(0, 0, width, height, 0, srcArray,data.getDataBuffer());
/*if (oneOfTwo)
copyLine1Of2(srcArray, (short[]) destBuffer.getElems(), sourceStepX);
else
copyLine2Of2(srcArray, (short[]) destBuffer.getElems(), sourceStepX);*/
return samples;
}