本文整理汇总了Java中java.awt.image.SampleModel.getSampleSize方法的典型用法代码示例。如果您正苦于以下问题:Java SampleModel.getSampleSize方法的具体用法?Java SampleModel.getSampleSize怎么用?Java SampleModel.getSampleSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.SampleModel
的用法示例。
在下文中一共展示了SampleModel.getSampleSize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canEncodeImage
import java.awt.image.SampleModel; //导入方法依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
SampleModel sampleModel = type.getSampleModel();
// Find the maximum bit depth across all channels
int[] sampleSize = sampleModel.getSampleSize();
int bitDepth = sampleSize[0];
for (int i = 1; i < sampleSize.length; i++) {
if (sampleSize[i] > bitDepth) {
bitDepth = sampleSize[i];
}
}
// 4450894: Ensure bitDepth is between 1 and 8
if (bitDepth < 1 || bitDepth > 8) {
return false;
}
return true;
}
示例2: canEncodeImage
import java.awt.image.SampleModel; //导入方法依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
if (type == null) {
throw new IllegalArgumentException("type == null!");
}
SampleModel sm = type.getSampleModel();
ColorModel cm = type.getColorModel();
boolean canEncode = sm.getNumBands() == 1 &&
sm.getSampleSize(0) <= 8 &&
sm.getWidth() <= 65535 &&
sm.getHeight() <= 65535 &&
(cm == null || cm.getComponentSize()[0] <= 8);
if (canEncode) {
return true;
} else {
return PaletteBuilder.canCreatePalette(type);
}
}
示例3: areSampleSizesEqual
import java.awt.image.SampleModel; //导入方法依赖的package包/类
/**
* Returns whether all samples have the same number of bits.
*/
private static boolean areSampleSizesEqual(SampleModel sm) {
boolean allSameSize = true;
int[] sampleSize = sm.getSampleSize();
int sampleSize0 = sampleSize[0];
int numBands = sampleSize.length;
for(int i = 1; i < numBands; i++) {
if(sampleSize[i] != sampleSize0) {
allSameSize = false;
break;
}
}
return allSameSize;
}
示例4: needToCreateIndex
import java.awt.image.SampleModel; //导入方法依赖的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;
}
示例5: canEncodeImage
import java.awt.image.SampleModel; //导入方法依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
SampleModel sm = type.getSampleModel();
if (!(sm instanceof MultiPixelPackedSampleModel))
return false;
if (sm.getSampleSize(0) != 1)
return false;
return true;
}
示例6: createColorTable
import java.awt.image.SampleModel; //导入方法依赖的package包/类
/**
* Create a color table from the image ColorModel and SampleModel.
*/
private static byte[] createColorTable(ColorModel colorModel,
SampleModel sampleModel)
{
byte[] colorTable;
if (colorModel instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel)colorModel;
int mapSize = icm.getMapSize();
/**
* The GIF image format assumes that size of image palette
* is power of two. We will use closest larger power of two
* as size of color table.
*/
int ctSize = getGifPaletteSize(mapSize);
byte[] reds = new byte[ctSize];
byte[] greens = new byte[ctSize];
byte[] blues = new byte[ctSize];
icm.getReds(reds);
icm.getGreens(greens);
icm.getBlues(blues);
/**
* fill tail of color component arrays by replica of first color
* in order to avoid appearance of extra colors in the color table
*/
for (int i = mapSize; i < ctSize; i++) {
reds[i] = reds[0];
greens[i] = greens[0];
blues[i] = blues[0];
}
colorTable = new byte[3*ctSize];
int idx = 0;
for (int i = 0; i < ctSize; i++) {
colorTable[idx++] = reds[i];
colorTable[idx++] = greens[i];
colorTable[idx++] = blues[i];
}
} else if (sampleModel.getNumBands() == 1) {
// create gray-scaled color table for single-banded images
int numBits = sampleModel.getSampleSize()[0];
if (numBits > 8) {
numBits = 8;
}
int colorTableLength = 3*(1 << numBits);
colorTable = new byte[colorTableLength];
for (int i = 0; i < colorTableLength; i++) {
colorTable[i] = (byte)(i/3);
}
} else {
// We do not have enough information here
// to create well-fit color table for RGB image.
colorTable = null;
}
return colorTable;
}
示例7: checkSampleModel
import java.awt.image.SampleModel; //导入方法依赖的package包/类
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
示例8: canEncodeImage
import java.awt.image.SampleModel; //导入方法依赖的package包/类
public boolean canEncodeImage(ImageTypeSpecifier type) {
SampleModel sampleModel = type.getSampleModel();
ColorModel colorModel = type.getColorModel();
// Find the maximum bit depth across all channels
int[] sampleSize = sampleModel.getSampleSize();
int bitDepth = sampleSize[0];
for (int i = 1; i < sampleSize.length; i++) {
if (sampleSize[i] > bitDepth) {
bitDepth = sampleSize[i];
}
}
// Ensure bitDepth is between 1 and 16
if (bitDepth < 1 || bitDepth > 16) {
return false;
}
// Check number of bands, alpha
int numBands = sampleModel.getNumBands();
if (numBands < 1 || numBands > 4) {
return false;
}
boolean hasAlpha = colorModel.hasAlpha();
// Fix 4464413: PNGTransparency reg-test was failing
// because for IndexColorModels that have alpha,
// numBands == 1 && hasAlpha == true, thus causing
// the check below to fail and return false.
if (colorModel instanceof IndexColorModel) {
return true;
}
if ((numBands == 1 || numBands == 3) && hasAlpha) {
return false;
}
if ((numBands == 2 || numBands == 4) && !hasAlpha) {
return false;
}
return true;
}