本文整理汇总了Java中java.awt.image.VolatileImage.IMAGE_OK属性的典型用法代码示例。如果您正苦于以下问题:Java VolatileImage.IMAGE_OK属性的具体用法?Java VolatileImage.IMAGE_OK怎么用?Java VolatileImage.IMAGE_OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.image.VolatileImage
的用法示例。
在下文中一共展示了VolatileImage.IMAGE_OK属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateOffscreenImage
private int updateOffscreenImage() {
// Update offscreen image reference
if (offscreenImage == null) offscreenImage = offscreenImageReference.get();
// Offscreen image not available
if (offscreenImage == null) return VolatileImage.IMAGE_INCOMPATIBLE;
// Buffered image is always valid
if (bufferType != BUFFER_VOLATILE_IMAGE) return VolatileImage.IMAGE_OK;
// Determine GraphicsConfiguration context
GraphicsConfiguration gConfiguration = getGraphicsConfiguration();
if (gConfiguration == null) return VolatileImage.IMAGE_INCOMPATIBLE;
// Return Volatile image state
return ((VolatileImage)offscreenImage).validate(gConfiguration);
}
示例2: render
public void render(Graphics g) {
do {
height = getBounds().height;
width = getBounds().width;
if (vimg == null) {
vimg = createVolatileImage(width, height);
renderOffscreen();
}
int returnCode = vimg.validate(getGraphicsConfiguration());
if (returnCode == VolatileImage.IMAGE_RESTORED) {
renderOffscreen();
} else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
vimg = getGraphicsConfiguration().
createCompatibleVolatileImage(width, height);
renderOffscreen();
} else if (returnCode == VolatileImage.IMAGE_OK) {
renderOffscreen();
}
g.drawImage(vimg, 0, 0, this);
} while (vimg.contentsLost());
}
示例3: test
private static void test(final BufferedImage bi) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
TRANSLUCENT);
BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
// draw to compatible Image
draw(bi, gold);
// draw to volatile image
int attempt = 0;
BufferedImage snapshot;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
vi.validate(gc);
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
draw(bi, vi);
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
// validate images
for (int x = 0; x < gold.getWidth(); ++x) {
for (int y = 0; y < gold.getHeight(); ++y) {
if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
ImageIO.write(gold, "png", new File("gold.png"));
ImageIO.write(snapshot, "png", new File("bi.png"));
throw new RuntimeException("Test failed.");
}
}
}
}
示例4: main
public static void main(final String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
AffineTransform at;
for (int size : SIZES) {
at = AffineTransform.getScaleInstance(size, size);
for (Shape clip : SHAPES) {
clip = at.createTransformedShape(clip);
for (Shape to : SHAPES) {
to = at.createTransformedShape(to);
// Prepare test images
BufferedImage snapshot;
BufferedImage bi = getBufferedImage(size);
VolatileImage vi = getVolatileImage(gc, size);
while (true) {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
draw(clip, to, bi, vi);
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
// Prepare gold images
BufferedImage goldvi = getCompatibleImage(gc, size);
BufferedImage goldbi = getBufferedImage(size);
draw(clip, to, goldbi, goldvi);
validate(snapshot, goldvi);
vi.flush();
}
}
}
}
示例5: main
public static void main(final String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
AffineTransform at;
for (int size : SIZES) {
at = AffineTransform.getScaleInstance(size, size);
for (Shape clip : SHAPES) {
clip = at.createTransformedShape(clip);
for (Shape to : SHAPES) {
to = at.createTransformedShape(to);
// Prepare test images
BufferedImage snapshot;
VolatileImage source = getVolatileImage(gc, size);
VolatileImage target = getVolatileImage(gc, size);
int attempt = 0;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
// Prepare source images
source.validate(gc);
Graphics2D g2d = source.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
if (source.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
// Prepare target images
target.validate(gc);
g2d = target.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
if (target.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
draw(clip, to, source, target);
snapshot = target.getSnapshot();
if (source.contentsLost() || target.contentsLost()) {
continue;
}
break;
}
// Prepare gold images
BufferedImage goldS = getSourceGold(gc, size);
BufferedImage goldT = getTargetGold(gc, size);
draw(clip, to, goldS, goldT);
validate(snapshot, goldT);
source.flush();
target.flush();
}
}
}
}