当前位置: 首页>>代码示例>>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;未经允许,请勿转载。