當前位置: 首頁>>代碼示例>>Java>>正文


Java RenderedImage.getColorModel方法代碼示例

本文整理匯總了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();
	}
}
 
開發者ID:GDSRS,項目名稱:TrabalhoFinalEDA2,代碼行數:39,代碼來源:mxPngEncodeParam.java

示例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;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:GIFImageWriter.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:PaletteBuilder.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:68,代碼來源:RenderableImageProducer.java

示例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();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:ImageTypeSpecifier.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ImageTypeSpecifier.java


注:本文中的java.awt.image.RenderedImage.getColorModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。