本文整理汇总了Java中java.awt.image.WritableRaster.getSampleModel方法的典型用法代码示例。如果您正苦于以下问题:Java WritableRaster.getSampleModel方法的具体用法?Java WritableRaster.getSampleModel怎么用?Java WritableRaster.getSampleModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.WritableRaster
的用法示例。
在下文中一共展示了WritableRaster.getSampleModel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reformatDiscontiguousData
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* Reformats bit-discontiguous data into the {@code DataBuffer}
* of the supplied {@code WritableRaster}.
*/
private static void reformatDiscontiguousData(byte[] buf,
int[] bitsPerSample,
int stride,
int w,
int h,
WritableRaster raster)
throws IOException {
// Get SampleModel info.
SampleModel sm = raster.getSampleModel();
int numBands = sm.getNumBands();
// Initialize input stream.
ByteArrayInputStream is = new ByteArrayInputStream(buf);
ImageInputStream iis = new MemoryCacheImageInputStream(is);
// Reformat.
long iisPosition = 0L;
int y = raster.getMinY();
for(int j = 0; j < h; j++, y++) {
iis.seek(iisPosition);
int x = raster.getMinX();
for(int i = 0; i < w; i++, x++) {
for(int b = 0; b < numBands; b++) {
long bits = iis.readBits(bitsPerSample[b]);
raster.setSample(x, y, b, (int)bits);
}
}
iisPosition += stride;
}
}
示例2: imageIsContiguous
import java.awt.image.WritableRaster; //导入方法依赖的package包/类
/**
* Returns whether the image has contiguous data across rows.
*/
public static final boolean imageIsContiguous(RenderedImage image) {
SampleModel sm;
if(image instanceof BufferedImage) {
WritableRaster ras = ((BufferedImage)image).getRaster();
sm = ras.getSampleModel();
} else {
sm = image.getSampleModel();
}
if (sm instanceof ComponentSampleModel) {
// Ensure image rows samples are stored contiguously
// in a single bank.
ComponentSampleModel csm = (ComponentSampleModel)sm;
if (csm.getPixelStride() != csm.getNumBands()) {
return false;
}
int[] bandOffsets = csm.getBandOffsets();
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] != i) {
return false;
}
}
int[] bankIndices = csm.getBankIndices();
for (int i = 0; i < bandOffsets.length; i++) {
if (bankIndices[i] != 0) {
return false;
}
}
return true;
}
// Otherwise true if and only if it's a bilevel image with
// a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
// pixel stride.
return ImageUtil.isBinary(sm);
}