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


Java SampleModel.getSampleSize方法代碼示例

本文整理匯總了Java中java.awt.image.SampleModel.getSampleSize方法的典型用法代碼示例。如果您正苦於以下問題:Java SampleModel.getSampleSize方法的具體用法?Java SampleModel.getSampleSize怎麽用?Java SampleModel.getSampleSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.image.SampleModel的用法示例。


在下文中一共展示了SampleModel.getSampleSize方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: canEncodeImage

import java.awt.image.SampleModel; //導入方法依賴的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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:JPEGImageWriterSpi.java

示例2: 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

示例3: areSampleSizesEqual

import java.awt.image.SampleModel; //導入方法依賴的package包/類
/**
 * Returns whether all samples have the same number of bits.
 */
private static boolean areSampleSizesEqual(SampleModel sm) {
    boolean allSameSize = true;
    int[] sampleSize = sm.getSampleSize();
    int sampleSize0 = sampleSize[0];
    int numBands = sampleSize.length;

    for(int i = 1; i < numBands; i++) {
        if(sampleSize[i] != sampleSize0) {
            allSameSize = false;
            break;
        }
    }

    return allSameSize;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TIFFDecompressor.java

示例4: needToCreateIndex

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

示例5: canEncodeImage

import java.awt.image.SampleModel; //導入方法依賴的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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:WBMPImageWriterSpi.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:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:WBMPImageWriter.java

示例8: 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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:42,代碼來源:PNGImageWriterSpi.java


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