本文整理汇总了Java中java.awt.image.RenderedImage.getColorModel方法的典型用法代码示例。如果您正苦于以下问题:Java RenderedImage.getColorModel方法的具体用法?Java RenderedImage.getColorModel怎么用?Java RenderedImage.getColorModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.RenderedImage
的用法示例。
在下文中一共展示了RenderedImage.getColorModel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: PaletteBuilder
import java.awt.image.RenderedImage; //导入方法依赖的package包/类
protected PaletteBuilder(RenderedImage src, int size) {
this.src = src;
this.srcColorModel = src.getColorModel();
this.srcRaster = src.getData();
this.transparency =
srcColorModel.getTransparency();
this.requiredSize = size;
}
示例4: run
import java.awt.image.RenderedImage; //导入方法依赖的package包/类
/**
* The runnable method for this class. This will produce an image using
* the current RenderableImage and RenderContext and send it to all the
* ImageConsumer currently registered with this class.
*/
public void run() {
// First get the rendered image
RenderedImage rdrdImage;
if (rc != null) {
rdrdImage = rdblImage.createRendering(rc);
} else {
rdrdImage = rdblImage.createDefaultRendering();
}
// And its ColorModel
ColorModel colorModel = rdrdImage.getColorModel();
Raster raster = rdrdImage.getData();
SampleModel sampleModel = raster.getSampleModel();
DataBuffer dataBuffer = raster.getDataBuffer();
if (colorModel == null) {
colorModel = ColorModel.getRGBdefault();
}
int minX = raster.getMinX();
int minY = raster.getMinY();
int width = raster.getWidth();
int height = raster.getHeight();
Enumeration<ImageConsumer> icList;
ImageConsumer ic;
// Set up the ImageConsumers
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = icList.nextElement();
ic.setDimensions(width,height);
ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
ImageConsumer.COMPLETESCANLINES |
ImageConsumer.SINGLEPASS |
ImageConsumer.SINGLEFRAME);
}
// Get RGB pixels from the raster scanline by scanline and
// send to consumers.
int pix[] = new int[width];
int i,j;
int numBands = sampleModel.getNumBands();
int tmpPixel[] = new int[numBands];
for (j = 0; j < height; j++) {
for(i = 0; i < width; i++) {
sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
pix[i] = colorModel.getDataElement(tmpPixel, 0);
}
// Now send the scanline to the Consumers
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = icList.nextElement();
ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
}
}
// Now tell the consumers we're done.
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = icList.nextElement();
ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
}
}
示例5: 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();
}
示例6: 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();
}