本文整理汇总了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;
}
示例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.");
}