本文整理匯總了Java中javax.imageio.ImageTypeSpecifier.getSampleModel方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageTypeSpecifier.getSampleModel方法的具體用法?Java ImageTypeSpecifier.getSampleModel怎麽用?Java ImageTypeSpecifier.getSampleModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.ImageTypeSpecifier
的用法示例。
在下文中一共展示了ImageTypeSpecifier.getSampleModel方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的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 javax.imageio.ImageTypeSpecifier; //導入方法依賴的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: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的package包/類
public boolean canEncodeImage(ImageTypeSpecifier type) {
int dataType= type.getSampleModel().getDataType();
if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
return false;
SampleModel sm = type.getSampleModel();
int numBands = sm.getNumBands();
if (!(numBands == 1 || numBands == 3))
return false;
if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
return false;
if (dataType > DataBuffer.TYPE_BYTE &&
!(sm instanceof SinglePixelPackedSampleModel))
return false;
return true;
}
示例4: prepareInsertEmpty
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的package包/類
public void prepareInsertEmpty(int imageIndex,
ImageTypeSpecifier imageType,
int width,
int height,
IIOMetadata imageMetadata,
List<? extends BufferedImage> thumbnails,
ImageWriteParam param) throws IOException {
checkParamsEmpty(imageType, width, height, thumbnails);
this.isInsertingEmpty = true;
SampleModel emptySM = imageType.getSampleModel();
RenderedImage emptyImage =
new EmptyImage(0, 0, width, height,
0, 0, emptySM.getWidth(), emptySM.getHeight(),
emptySM, imageType.getColorModel());
insert(imageIndex, new IIOImage(emptyImage, null, imageMetadata),
param, false);
}
示例5: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的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: prepareWriteEmpty
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的package包/類
public void prepareWriteEmpty(IIOMetadata streamMetadata,
ImageTypeSpecifier imageType,
int width,
int height,
IIOMetadata imageMetadata,
List<? extends BufferedImage> thumbnails,
ImageWriteParam param) throws IOException {
if (stream == null) {
throw new IllegalStateException("output == null!");
}
checkParamsEmpty(imageType, width, height, thumbnails);
this.isWritingEmpty = true;
SampleModel emptySM = imageType.getSampleModel();
RenderedImage emptyImage =
new EmptyImage(0, 0, width, height,
0, 0, emptySM.getWidth(), emptySM.getHeight(),
emptySM, imageType.getColorModel());
markPositions();
write(streamMetadata, new IIOImage(emptyImage, null, imageMetadata),
param, true, false);
if (abortRequested()) {
resetPositions();
}
}
示例7: getDefaultImageMetadata
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的package包/類
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param) {
GIFWritableImageMetadata imageMetadata =
new GIFWritableImageMetadata();
// Image dimensions
SampleModel sampleModel = imageType.getSampleModel();
Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
sampleModel.getHeight());
Dimension destSize = new Dimension();
computeRegions(sourceBounds, destSize, param);
imageMetadata.imageWidth = destSize.width;
imageMetadata.imageHeight = destSize.height;
// Interlacing
if (param != null && param.canWriteProgressive() &&
param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
imageMetadata.interlaceFlag = false;
} else {
imageMetadata.interlaceFlag = true;
}
// Local color table
ColorModel colorModel = imageType.getColorModel();
imageMetadata.localColorTable =
createColorTable(colorModel, sampleModel);
// Transparency
if (colorModel instanceof IndexColorModel) {
int transparentIndex =
((IndexColorModel)colorModel).getTransparentPixel();
if (transparentIndex != -1) {
imageMetadata.transparentColorFlag = true;
imageMetadata.transparentColorIndex = transparentIndex;
}
}
return imageMetadata;
}
示例8: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的package包/類
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
ImageWriterSpi spi = this.getOriginatingProvider();
if (!spi.canEncodeImage(imgType)) {
return false;
}
int biType = imgType.getBufferedImageType();
int bpp = imgType.getColorModel().getPixelSize();
if (compressionType == BI_RLE4 && bpp != 4) {
// only 4bpp images can be encoded as BI_RLE4
return false;
}
if (compressionType == BI_RLE8 && bpp != 8) {
// only 8bpp images can be encoded as BI_RLE8
return false;
}
if (bpp == 16) {
/*
* Technically we expect that we may be able to
* encode only some of SinglePixelPackedSampleModel
* images here.
*
* In addition we should take into account following:
*
* 1. BI_RGB case, according to the MSDN description:
*
* The bitmap has a maximum of 2^16 colors. If the
* biCompression member of the BITMAPINFOHEADER is BI_RGB,
* the bmiColors member of BITMAPINFO is NULL. Each WORD
* in the bitmap array represents a single pixel. The
* relative intensities of red, green, and blue are
* represented with five bits for each color component.
*
* 2. BI_BITFIELDS case, according ot the MSDN description:
*
* Windows 95/98/Me: When the biCompression member is
* BI_BITFIELDS, the system supports only the following
* 16bpp color masks: A 5-5-5 16-bit image, where the blue
* mask is 0x001F, the green mask is 0x03E0, and the red mask
* is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
* is 0x001F, the green mask is 0x07E0, and the red mask is
* 0xF800.
*/
boolean canUseRGB = false;
boolean canUseBITFIELDS = false;
SampleModel sm = imgType.getSampleModel();
if (sm instanceof SinglePixelPackedSampleModel) {
int[] sizes =
((SinglePixelPackedSampleModel)sm).getSampleSize();
canUseRGB = true;
canUseBITFIELDS = true;
for (int i = 0; i < sizes.length; i++) {
canUseRGB &= (sizes[i] == 5);
canUseBITFIELDS &= ((sizes[i] == 5) ||
(i == 1 && sizes[i] == 6));
}
}
return (((compressionType == BI_RGB) && canUseRGB) ||
((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
}
return true;
}
示例9: canEncodeImage
import javax.imageio.ImageTypeSpecifier; //導入方法依賴的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;
}