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


Java IndexColorModel類代碼示例

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


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

示例1: createIndexImage

import java.awt.image.IndexColorModel; //導入依賴的package包/類
private BufferedImage createIndexImage(int bpp) {
    // calculate palette size
    int psize = (1 << bpp);

    // prepare palette;
    byte[] r = new byte[psize];
    byte[] g = new byte[psize];
    byte[] b = new byte[psize];

    for (int i = 0; i < colors.length; i++) {
        r[i] = (byte)(0xff & colors[i].getRed());
        g[i] = (byte)(0xff & colors[i].getGreen());
        b[i] = (byte)(0xff & colors[i].getBlue());
    }

    // now prepare appropriate index clor model
    IndexColorModel icm = new IndexColorModel(bpp, psize, r, g, b);

    return new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:BMPSubsamplingTest.java

示例2: write

import java.awt.image.IndexColorModel; //導入依賴的package包/類
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:JFIFMarkerSegment.java

示例3: gethISTNode

import java.awt.image.IndexColorModel; //導入依賴的package包/類
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

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

示例4: encodeRLE4Test

import java.awt.image.IndexColorModel; //導入依賴的package包/類
private static void encodeRLE4Test() throws IOException {
    // create 4bpp image
    byte[] r = new byte[16];
    r[0] = (byte)0xff;
    byte[] g = new byte[16];
    g[1] = (byte)0xff;
    byte[] b = new byte[16];
    b[2] = (byte)0xff;
    IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);

    BufferedImage bimg = new BufferedImage(100, 100,
                                           BufferedImage.TYPE_BYTE_BINARY,
                                           icm);

    Graphics gr = bimg.getGraphics();
    gr.setColor(Color.green);
    gr.fillRect(0, 0, 100, 100);

    doTest(bimg, "BI_RLE4", ImageWriteParam.MODE_EXPLICIT);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:RleEncodingTest.java

示例5: FloatColorMap

import java.awt.image.IndexColorModel; //導入依賴的package包/類
/**
 * Constructs a color map with more than one color components.
 * @param f arrays of floats, one array for each color component.
 * @param ic array index of the component for the index color model.
 * @param icm the index color model corresponding to one component.
 */
public FloatColorMap(float[][][] f, int ic, IndexColorModel icm) {
  super(icm);
  Check.argument(
    f.length==1 || f.length==3 || f.length==4,
    "number of arrays (color components) equals 1, 3, or 4");
  int nc = f.length;
  FloatByteMap[] fbm = new FloatByteMap[nc];
  for (int jc=0; jc<nc; ++jc)
    fbm[jc] = new FloatByteMap(f[jc]);
  _fbmi0 = fbm[0];
  _fbmi1 = (nc>1)?fbm[1]:fbm[0];
  _fbmi2 = (nc>1)?fbm[2]:fbm[0];
  _fbmi3 = (nc>3)?fbm[3]:null;
  _fbmic = fbm[ic];
}
 
開發者ID:MinesJTK,項目名稱:jtk,代碼行數:22,代碼來源:FloatColorMap.java

示例6: Setup

import java.awt.image.IndexColorModel; //導入依賴的package包/類
private void Setup() {
    balls = new Image[nBalls];
    byte red[] = new byte[256];
    red[0] = (byte) bgGrey;
    byte green[] = new byte[256];
    green[0] = (byte) bgGrey;
    byte blue[] = new byte[256];
    blue[0] = (byte) bgGrey;
    for (int r = 0; r < nBalls; r++) {
        float b = (float) (r + 1) / nBalls;
        for (int i = maxr; i >= 1; --i) {
            float d = (float) i / maxr;
            red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b);
            green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b);
            blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b);
        }
        IndexColorModel model = new IndexColorModel(8, maxr + 1,
                red, green, blue, 0);
        balls[r] = applet.createImage(
                new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:XYZApp.java

示例7: createIndexedBitmaskColorModel

import java.awt.image.IndexColorModel; //導入依賴的package包/類
protected  static IndexColorModel createIndexedBitmaskColorModel() {
    int paletteSize = 8;
    byte[] red = new byte[paletteSize];
    byte[] green = new byte[paletteSize];
    byte[] blue = new byte[paletteSize];

    red[0] = (byte)0xff; green[0] = (byte)0x00; blue[0] = (byte)0x00;
    red[1] = (byte)0x00; green[1] = (byte)0xff; blue[1] = (byte)0x00;
    red[2] = (byte)0x00; green[2] = (byte)0x00; blue[2] = (byte)0xff;
    red[3] = (byte)0xff; green[3] = (byte)0xff; blue[3] = (byte)0xff;
    red[4] = (byte)0x00; green[4] = (byte)0x00; blue[4] = (byte)0x00;
    red[5] = (byte)0x80; green[5] = (byte)0x80; blue[5] = (byte)0x80;
    red[6] = (byte)0xff; green[6] = (byte)0xff; blue[6] = (byte)0x00;
    red[7] = (byte)0x00; green[7] = (byte)0xff; blue[7] = (byte)0xff;

    int numBits = 3;

    IndexColorModel icm = new IndexColorModel(numBits, paletteSize,
                                              red, green, blue, 5);

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

示例8: setAlpha

import java.awt.image.IndexColorModel; //導入依賴的package包/類
/**
 * Returns an index color model with specified opacity (alpha).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha opacity in the range [0.0,1.0].
 * @return the index color model with alpha.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, double alpha) {
  int bits = icm.getPixelSize();
  int size = icm.getMapSize();
  byte[] r = new byte[size];
  byte[] g = new byte[size];
  byte[] b = new byte[size];
  byte[] a = new byte[size];
  icm.getReds(r);
  icm.getGreens(g);
  icm.getBlues(b);
  byte ia = (byte)(255.0*alpha+0.5);
  for (int i=0; i<size; ++i)
    a[i] = ia;
  return new IndexColorModel(bits,size,r,g,b,a);
}
 
開發者ID:MinesJTK,項目名稱:jtk,代碼行數:22,代碼來源:ColorMap.java

示例9: verifyEquals

import java.awt.image.IndexColorModel; //導入依賴的package包/類
private static void verifyEquals(IndexColorModel m1,
                                 IndexColorModel m2) {
    if (m1.equals(null)) {
        throw new RuntimeException("equals(null) returns true");
    }
    if (!(m1.equals(m2))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (!(m2.equals(m1))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (m1.hashCode() != m2.hashCode()) {
        throw new RuntimeException("HashCode is not same for same"
                + " IndexColorModels");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:IndexColorModelEqualsTest.java

示例10: createDataBC

import java.awt.image.IndexColorModel; //導入依賴的package包/類
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank,
                                       double scaleX, double scaleY)
{
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType,
                              scaleX, scaleY);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:BufImgSurfaceData.java

示例11: getDefaultPalette

import java.awt.image.IndexColorModel; //導入依賴的package包/類
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:GIFImageReader.java

示例12: createColorModel

import java.awt.image.IndexColorModel; //導入依賴的package包/類
public static IndexColorModel createColorModel() {
    // Create a 6x6x6 color cube
    int[] cmap = new int[256];
    int i = 0;
    for (int r = 0; r < 256; r += 51) {
        for (int g = 0; g < 256; g += 51) {
            for (int b = 0; b < 256; b += 51) {
                cmap[i++] = (r << 16) | (g << 8) | b;
            }
        }
    }
    // And populate the rest of the cmap with gray values
    int grayIncr = 256 / (256 - i);

    // The gray ramp will be between 18 and 252
    int gray = grayIncr * 3;
    for (; i < 256; i++) {
        cmap[i] = (gray << 16) | (gray << 8) | gray;
        gray += grayIncr;
    }

    return new IndexColorModel(8, 256, cmap, 0, false, -1,
            DataBuffer.TYPE_BYTE);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:25,代碼來源:IDLColorModelFactory.java

示例13: createDataSC

import java.awt.image.IndexColorModel; //導入依賴的package包/類
public static SurfaceData createDataSC(BufferedImage bImg,
                                       SurfaceType sType,
                                       IndexColorModel icm) {
    ShortComponentRaster scRaster =
        (ShortComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(scRaster.getDataBuffer(), bImg, sType);
    bisd.initRaster(scRaster.getDataStorage(),
                    scRaster.getDataOffset(0) * 2, 0,
                    scRaster.getWidth(),
                    scRaster.getHeight(),
                    scRaster.getPixelStride() * 2,
                    scRaster.getScanlineStride() * 2,
                    icm);
    return bisd;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:BufImgSurfaceData.java

示例14: createDataBC

import java.awt.image.IndexColorModel; //導入依賴的package包/類
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank) {
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:BufImgSurfaceData.java

示例15: createDataBP

import java.awt.image.IndexColorModel; //導入依賴的package包/類
public static SurfaceData createDataBP(BufferedImage bImg,
                                       SurfaceType sType) {
    BytePackedRaster bpRaster =
        (BytePackedRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bpRaster.getDataStorage(),
                    bpRaster.getDataBitOffset() / 8,
                    bpRaster.getDataBitOffset() & 7,
                    bpRaster.getWidth(),
                    bpRaster.getHeight(),
                    0,
                    bpRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:BufImgSurfaceData.java


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