当前位置: 首页>>代码示例>>Java>>正文


Java SampleModel.getNumBands方法代码示例

本文整理汇总了Java中java.awt.image.SampleModel.getNumBands方法的典型用法代码示例。如果您正苦于以下问题:Java SampleModel.getNumBands方法的具体用法?Java SampleModel.getNumBands怎么用?Java SampleModel.getNumBands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.SampleModel的用法示例。


在下文中一共展示了SampleModel.getNumBands方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:GIFImageWriterSpi.java

示例2: getElementSize

import java.awt.image.SampleModel; //导入方法依赖的package包/类
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ImageUtil.java

示例3: canEncodeImage

import java.awt.image.SampleModel; //导入方法依赖的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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:BMPImageWriterSpi.java

示例4: getDefaultEncodeParam

import java.awt.image.SampleModel; //导入方法依赖的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

示例5: reformatDiscontiguousData

import java.awt.image.SampleModel; //导入方法依赖的package包/类
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:TIFFDecompressor.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:62,代码来源:GIFImageWriter.java

示例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"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:WBMPImageWriter.java

示例8: isBinary

import java.awt.image.SampleModel; //导入方法依赖的package包/类
public static boolean isBinary(SampleModel sm) {
    return sm instanceof MultiPixelPackedSampleModel &&
        ((MultiPixelPackedSampleModel)sm).getPixelBitStride() == 1 &&
        sm.getNumBands() == 1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:ImageUtil.java

示例9: 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:PNGImageWriterSpi.java

示例10: run

import java.awt.image.SampleModel; //导入方法依赖的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


注:本文中的java.awt.image.SampleModel.getNumBands方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。