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


Java IndexColorModel.createCompatibleWritableRaster方法代碼示例

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


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

示例1: createFrame

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
private static BufferedImage createFrame(int[] palette) {
    IndexColorModel icm = new IndexColorModel(getNumBits(palette.length),
        palette.length, palette, 0, false, -1, DataBuffer.TYPE_BYTE);
    WritableRaster wr = icm.createCompatibleWritableRaster(w, h);
    int[] samples = new int[w * h];
    Arrays.fill(samples, 0);
    wr.setSamples(0, 0, w, h, 0, samples);

    BufferedImage img = new BufferedImage(icm, wr, false, null);
    return img;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:LUTCompareTest.java

示例2: main

import java.awt.image.IndexColorModel; //導入方法依賴的package包/類
public static void main(String[] args) {
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() <= 8) {
        System.out.println("8-bit color model, test considered passed");
        return;
    }

    /*
     * Set up images:
     * 1.) VolatileImge for rendering to,
     * 2.) BufferedImage for reading back the contents of the VI
     * 3.) The image triggering the problem
     */
    VolatileImage vImg = null;
    BufferedImage readBackBImg;

    // create a BITMASK ICM such that the transparent color is
    // tr. black (and it's the first in the color map so a buffered image
    // created with this ICM is transparent
    byte r[] = { 0x00, (byte)0xff};
    byte g[] = { 0x00, (byte)0xff};
    byte b[] = { 0x00, (byte)0xff};
    IndexColorModel icm = new IndexColorModel(8, 2, r, g, b, 0);
    WritableRaster wr = icm.createCompatibleWritableRaster(25, 25);
    BufferedImage tImg = new BufferedImage(icm, wr, false, null);

    do {
        if (vImg == null ||
            vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE)
        {
            vImg = gc.createCompatibleVolatileImage(tImg.getWidth(),
                                                    tImg.getHeight());
        }

        Graphics viG = vImg.getGraphics();
        viG.setColor(Color.red);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());

        viG.drawImage(tImg, 0, 0, Color.green, null);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.white, null);

        readBackBImg = vImg.getSnapshot();
    } while (vImg.contentsLost());

    for (int x = 0; x < readBackBImg.getWidth(); x++) {
        for (int y = 0; y < readBackBImg.getHeight(); y++) {
            int currPixel = readBackBImg.getRGB(x, y);
            if (currPixel != Color.white.getRGB()) {
                String fileName = "DrawImageBgTest.png";
                try {
                    ImageIO.write(readBackBImg, "png", new File(fileName));
                    System.err.println("Dumped image to " + fileName);
                } catch (IOException ex) {}
                throw new
                    RuntimeException("Test Failed: found wrong color: 0x"+
                                     Integer.toHexString(currPixel));
            }
        }
    }
    System.out.println("Test Passed.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:66,代碼來源:DrawImageBgTest.java


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