本文整理汇总了Java中javax.imageio.ImageReadParam.getSourceRegion方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReadParam.getSourceRegion方法的具体用法?Java ImageReadParam.getSourceRegion怎么用?Java ImageReadParam.getSourceRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageReadParam
的用法示例。
在下文中一共展示了ImageReadParam.getSourceRegion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkImageReadParam
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
/**
* <p>
* Validate that the specified {@link javax.imageio.ImageReadParam} contains
* only the default values. If non-default values are present,
* {@link java.io.IOException} is thrown.
* </p>
*
* @param param
* the <code>ImageReadParam</code> to be validated
* @param head
* the <code>TGAHeader</code> that contains information about the
* source image
* @throws IOException
* if the <code>ImageReadParam</code> contains non-default
* values
*/
private void checkImageReadParam(final ImageReadParam param, final TGAHeader header) throws IOException {
if (param != null) {
// get the image height and width from the header for convenience
final int width = header.getWidth();
final int height = header.getHeight();
// ensure that the param contains only the defaults
final Rectangle sourceROI = param.getSourceRegion();
if ((sourceROI != null) && ((sourceROI.x != 0) || (sourceROI.y != 0) || (sourceROI.width != width) || (sourceROI.height != height))) {
throw new IOException("The source region of interest is not the default."); // FIXME:
// localize
} /* else -- the source ROI is the default */
final Rectangle destinationROI = param.getSourceRegion();
if ((destinationROI != null) && ((destinationROI.x != 0) || (destinationROI.y != 0) || (destinationROI.width != width) || (destinationROI.height != height))) {
throw new IOException("The destination region of interest is not the default."); // FIXME:
// localize
} /* else -- the destination ROI is the default */
if ((param.getSourceXSubsampling() != 1) || (param.getSourceYSubsampling() != 1)) {
throw new IOException("Source sub-sampling is not supported."); // FIXME:
// localize
} /* else -- sub-sampling is the default */
} /* else -- the ImageReadParam is null so the defaults *are* used */
}
示例2: checkImageReadParam
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
/**
* <p>Validate that the specified {@link javax.imageio.ImageReadParam}
* contains only the default values. If non-default values are present,
* {@link java.io.IOException} is thrown.</p>
*
* @param param the <code>ImageReadParam</code> to be validated
* @param head the <code>TGAHeader</code> that contains information about
* the source image
* @throws IOException if the <code>ImageReadParam</code> contains non-default
* values
*/
private void checkImageReadParam(final ImageReadParam param,
final TGAHeader header)
throws IOException
{
if(param != null)
{
// get the image height and width from the header for convenience
final int width = header.getWidth();
final int height = header.getHeight();
// ensure that the param contains only the defaults
final Rectangle sourceROI = param.getSourceRegion();
if( (sourceROI != null) &&
( (sourceROI.x != 0) || (sourceROI.y != 0) ||
(sourceROI.width != width) || (sourceROI.height != height) ) )
{
throw new IOException("The source region of interest is not the default."); // FIXME: localize
} /* else -- the source ROI is the default */
final Rectangle destinationROI = param.getSourceRegion();
if( (destinationROI != null) &&
( (destinationROI.x != 0) || (destinationROI.y != 0) ||
(destinationROI.width != width) || (destinationROI.height != height) ) )
{
throw new IOException("The destination region of interest is not the default."); // FIXME: localize
} /* else -- the destination ROI is the default */
if( (param.getSourceXSubsampling() != 1) ||
(param.getSourceYSubsampling() != 1) )
{
throw new IOException("Source sub-sampling is not supported."); // FIXME: localize
} /* else -- sub-sampling is the default */
} /* else -- the ImageReadParam is null so the defaults *are* used */
}
示例3: read
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
@Override
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
checkIndex(imageIndex);
ByteBuffer data = jpegData;
try {
int rotation = 0;
Rectangle region = null;
Rectangle extraCrop = null;
if (param instanceof TurboJpegImageReadParam) {
rotation = ((TurboJpegImageReadParam) param).getRotationDegree();
}
if (param != null && param.getSourceRegion() != null) {
region = param.getSourceRegion();
scaleRegion(imageIndex, region);
if (region.x + region.width == getWidth(0)) {
region.width = 0;
}
if (region.y + region.height == getHeight(0)) {
region.height = 0;
}
if (!isRegionFullImage(imageIndex, region)) {
extraCrop = adjustRegion(info.getMCUSize(), region, rotation);
} else {
region = null;
}
}
if (region != null || rotation != 0) {
data = lib.transform(data.array(), info, region, rotation);
}
Info transformedInfo = lib.getInfo(data.array());
BufferedImage img = lib.decode(
data.array(), transformedInfo, transformedInfo.getAvailableSizes().get(imageIndex));
if (extraCrop != null) {
adjustExtraCrop(imageIndex, transformedInfo, extraCrop);
img = img.getSubimage(extraCrop.x, extraCrop.y, extraCrop.width, extraCrop.height);
}
return img;
} catch (TurboJpegException e) {
throw new IOException(e);
}
}
示例4: readRaster
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
/**
* Read the raw raster data from the image, without any LUTs being applied.
* Cannot read overlay data, as it isn't clear what the raster format should
* be for those.
*/
@Override
public Raster readRaster(int imageIndex, ImageReadParam param)
throws IOException {
initImageReader(imageIndex);
if (param == null) {
param = getDefaultReadParam();
}
if (compressed) {
ImageReadParam param1 = reader.getDefaultReadParam();
copyReadParam(param, param1);
return decompressRaster(imageIndex, param1);
}
if( pmi.endsWith("422") || pmi.endsWith("420") ) {
log.debug("Using a 422/420 partial component image reader.");
if( param.getSourceXSubsampling()!=1
|| param.getSourceYSubsampling()!=1
|| param.getSourceRegion()!=null )
{
log.warn("YBR_*_422 and 420 reader does not support source sub-sampling or source region.");
throw new UnsupportedOperationException("Implement sub-sampling/soure region.");
}
SampleModel sm = createSampleModel();
WritableRaster wr = Raster.createWritableRaster(sm, new Point());
DataBufferByte dbb = (DataBufferByte) wr.getDataBuffer();
byte[] data = dbb.getData();
log.debug("Seeking to "+(pixelDataPos + imageIndex * data.length)+" and reading "+data.length+" bytes.");
iis.seek(pixelDataPos + imageIndex * data.length);
iis.read(data);
if (swapByteOrder) {
ByteUtils.toggleShortEndian(data);
}
return wr;
}
Raster raster = reader.readRaster(imageIndex, param);
if (swapByteOrder) {
ByteUtils.toggleShortEndian(
((DataBufferByte)raster.getDataBuffer()).getData());
}
return raster;
}