本文整理了Java中java.awt.image.ColorModel.getNumColorComponents()
方法的一些代码示例,展示了ColorModel.getNumColorComponents()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ColorModel.getNumColorComponents()
方法的具体详情如下:
包路径:java.awt.image.ColorModel
类名称:ColorModel
方法名:getNumColorComponents
[英]Returns the number of color components in this ColorModel
. This is the number of components returned by ColorSpace#getNumComponents.
[中]返回此ColorModel
中的颜色组件数。这是ColorSpace#getNumComponents返回的组件数。
代码示例来源:origin: geoserver/geoserver
private boolean hasAlphaBand(ColorModel cm) {
// num components returns the alpha, num _color_ components does not
return (cm.getNumComponents() == 2 && cm.getNumColorComponents() == 1) /* gray-alpha case */
|| (cm.getNumComponents() == 4 && cm.getNumColorComponents() == 3) /* rgba case */;
}
代码示例来源:origin: geoserver/geoserver
private int getAlphaBandIndex(GridCoverage2D coverage) {
final ColorModel cm = coverage.getRenderedImage().getColorModel();
if (!cm.hasAlpha() || cm.getNumComponents() == cm.getNumColorComponents()) {
throw new IllegalArgumentException(
"The source coverage does not have an alpha band, cannot extract an "
+ "alpha band");
}
// the alpha band is always the last (see ComponentColorModel.getAlphaRaster or the
// getAlpha(object) code
if (cm.getNumColorComponents() == 1) {
// gray-alpha
return 1;
} else {
// rgba/argb
return 3;
}
}
代码示例来源:origin: geotools/geotools
final int defNumCompOnents= defaultCM.getNumColorComponents();
int actualNumCompOnents= actualCM.getNumColorComponents();
int colorCompOnentsDifference= Math.abs(defNumComponents - actualNumComponents);
代码示例来源:origin: apache/pdfbox
this.bytesPerPixel = image.getColorModel().getNumColorComponents() * bytesPerComponent;
this.imageType = image.getType();
this.hasAlpha = image.getColorModel().getNumComponents() != image.getColorModel()
.getNumColorComponents();
this.alphaImageData = hasAlpha ? new byte[width * height * bytesPerComponent] : null;
代码示例来源:origin: dermotte/LIRE
public void extract(BufferedImage img) {
int image_t care
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace());
for (int i = 0; i
}
}
代码示例来源:origin: geotools/geotools
if (!cm.hasAlpha() && cm.getNumColorComponents() != 2) {
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testGetColorModelGIF() {
URL resource = getClass().getResource("/tux.gif");
assertNotNull(resource);
Image source = Toolkit.getDefaultToolkit().createImage(resource);
assertNotNull(source);
BufferedImageFactory factory = new BufferedImageFactory(source);
ColorModel colorModel = factory.getColorModel();
assertNotNull(colorModel);
assertEquals(3, colorModel.getNumColorComponents());
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace());
assertTrue(colorModel instanceof IndexColorModel);
assertTrue(colorModel.hasAlpha());
assertEquals(4, colorModel.getNumComponents());
assertTrue(((IndexColorModel) colorModel).getTransparentPixel() >= 0);
assertEquals(Transparency.BITMASK, colorModel.getTransparency());
for (int i = 0; i
}
}
代码示例来源:origin: geotools/geotools
+ " is not supported, cannot perform color blending on it");
} else if (cm instanceof ComponentColorModel && cm.getNumColorComponents() == 3) {
accessor = new ByteRgbAccessor(raster, cm.hasAlpha());
} else {
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testGray() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int [] {0}, false, false);
assertEquals(1, spec.getNumBands());
assertEquals(1, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertFalse(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(1, spec.getColorModel().getNumComponents());
assertEquals(1, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(1, spec.getSampleModel().getNumBands());
assertEquals(1, spec.getSampleModel().getNumDataElements());
}
代码示例来源:origin: geotools/geotools
final int numColorBands = cm.getNumColorComponents();
final boolean hasAlpha = cm.hasAlpha();
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testGrayAlpha() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int [] {0, 1}, true, false);
assertEquals(2, spec.getNumBands());
assertEquals(2, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(2, spec.getColorModel().getNumComponents());
assertEquals(1, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(2, spec.getSampleModel().getNumBands());
assertEquals(2, spec.getSampleModel().getNumDataElements());
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testRGB() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false);
assertEquals(3, spec.getNumBands());
assertEquals(3, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertEquals(32, spec.getBitsPerBand(2));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertFalse(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(3, spec.getColorModel().getNumComponents());
assertEquals(3, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(3, spec.getSampleModel().getNumBands());
assertEquals(3, spec.getSampleModel().getNumDataElements());
}
代码示例来源:origin: geotools/geotools
.getRenderedImage();
imageWorker.retainBands(mosaic.getColorModel().getNumColorComponents());
imageWorker.addBand(maskedAlpha, false, true, null);
} else {
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testRGBAlpha() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, false);
assertEquals(4, spec.getNumBands());
assertEquals(4, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(4, spec.getColorModel().getNumComponents());
assertEquals(3, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(4, spec.getSampleModel().getNumBands());
assertEquals(4, spec.getSampleModel().getNumDataElements());
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testCMYK() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(CMYK, new int [] {0, 1, 2, 3}, false, false);
assertEquals(4, spec.getNumBands());
assertEquals(4, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertFalse(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(4, spec.getColorModel().getNumComponents());
assertEquals(4, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(4, spec.getSampleModel().getNumBands());
assertEquals(4, spec.getSampleModel().getNumDataElements());
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testRGBAlphaPre() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, true);
assertEquals(4, spec.getNumBands());
assertEquals(4, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertTrue(spec.getColorModel().isAlphaPremultiplied());
assertEquals(4, spec.getColorModel().getNumComponents());
assertEquals(3, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(4, spec.getSampleModel().getNumBands());
assertEquals(4, spec.getSampleModel().getNumDataElements());
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testCMYKAlpha() {
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(CMYK, new int [] {0, 1, 2, 3, 4}, true, false);
assertEquals(5, spec.getNumBands());
assertEquals(5, spec.getNumComponents());
assertEquals(32, spec.getBitsPerBand(0));
assertEquals(32, spec.getBitsPerBand(1));
assertEquals(32, spec.getBitsPerBand(2));
assertEquals(32, spec.getBitsPerBand(3));
assertEquals(32, spec.getBitsPerBand(4));
assertThat(spec.getColorModel(), is(ComponentColorModel.class));
assertTrue(spec.getColorModel().hasAlpha());
assertFalse(spec.getColorModel().isAlphaPremultiplied());
assertEquals(5, spec.getColorModel().getNumComponents());
assertEquals(4, spec.getColorModel().getNumColorComponents());
assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class));
assertEquals(5, spec.getSampleModel().getNumBands());
assertEquals(5, spec.getSampleModel().getNumDataElements());
}