本文整理汇总了Java中java.awt.image.RenderedImage.getSampleModel方法的典型用法代码示例。如果您正苦于以下问题:Java RenderedImage.getSampleModel方法的具体用法?Java RenderedImage.getSampleModel怎么用?Java RenderedImage.getSampleModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.RenderedImage
的用法示例。
在下文中一共展示了RenderedImage.getSampleModel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultEncodeParam
import java.awt.image.RenderedImage; //导入方法依赖的package包/类
/**
* Returns an instance of <code>PNGEncodeParam.Palette</code>,
* <code>PNGEncodeParam.Gray</code>, or
* <code>PNGEncodeParam.RGB</code> appropriate for encoding
* the given image.
*
* <p> If the image has an <code>IndexColorModel</code>, an
* instance of <code>PNGEncodeParam.Palette</code> is returned.
* Otherwise, if the image has 1 or 2 bands an instance of
* <code>PNGEncodeParam.Gray</code> is returned. In all other
* cases an instance of <code>PNGEncodeParam.RGB</code> is
* returned.
*
* <p> Note that this method does not provide any guarantee that
* the given image will be successfully encoded by the PNG
* encoder, as it only performs a very superficial analysis of
* the image structure.
*/
public static mxPngEncodeParam getDefaultEncodeParam(RenderedImage im)
{
ColorModel colorModel = im.getColorModel();
if (colorModel instanceof IndexColorModel)
{
return new mxPngEncodeParam.Palette();
}
SampleModel sampleModel = im.getSampleModel();
int numBands = sampleModel.getNumBands();
if (numBands == 1 || numBands == 2)
{
return new mxPngEncodeParam.Gray();
}
else
{
return new mxPngEncodeParam.RGB();
}
}
示例2: needToCreateIndex
import java.awt.image.RenderedImage; //导入方法依赖的package包/类
private boolean needToCreateIndex(RenderedImage image) {
SampleModel sampleModel = image.getSampleModel();
ColorModel colorModel = image.getColorModel();
return sampleModel.getNumBands() != 1 ||
sampleModel.getSampleSize()[0] > 8 ||
colorModel.getComponentSize()[0] > 8;
}
示例3: imageIsContiguous
import java.awt.image.RenderedImage; //导入方法依赖的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);
}
示例4: ImageTypeSpecifier
import java.awt.image.RenderedImage; //导入方法依赖的package包/类
/**
* Constructs an <code>ImageTypeSpecifier</code> from a
* <code>RenderedImage</code>. If a <code>BufferedImage</code> is
* being used, one of the factory methods
* <code>createFromRenderedImage</code> or
* <code>createFromBufferedImageType</code> should be used instead in
* order to get a more accurate result.
*
* @param image a <code>RenderedImage</code>.
*
* @exception IllegalArgumentException if the argument is
* <code>null</code>.
*/
public ImageTypeSpecifier(RenderedImage image) {
if (image == null) {
throw new IllegalArgumentException("image == null!");
}
colorModel = image.getColorModel();
sampleModel = image.getSampleModel();
}
示例5: ImageTypeSpecifier
import java.awt.image.RenderedImage; //导入方法依赖的package包/类
/**
* Constructs an {@code ImageTypeSpecifier} from a
* {@code RenderedImage}. If a {@code BufferedImage} is
* being used, one of the factory methods
* {@code createFromRenderedImage} or
* {@code createFromBufferedImageType} should be used instead in
* order to get a more accurate result.
*
* @param image a {@code RenderedImage}.
*
* @exception IllegalArgumentException if the argument is
* {@code null}.
*/
public ImageTypeSpecifier(RenderedImage image) {
if (image == null) {
throw new IllegalArgumentException("image == null!");
}
colorModel = image.getColorModel();
sampleModel = image.getSampleModel();
}