本文整理汇总了Java中java.awt.image.VolatileImage类的典型用法代码示例。如果您正苦于以下问题:Java VolatileImage类的具体用法?Java VolatileImage怎么用?Java VolatileImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VolatileImage类属于java.awt.image包,在下文中一共展示了VolatileImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawBackingStoreImage
import java.awt.image.VolatileImage; //导入依赖的package包/类
private void drawBackingStoreImage(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
GraphicsConfiguration gc = g2d.getDeviceConfiguration();
if (vImg == null ||
vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
/* Create a new volatile image */
vImg = createVolatileImage(PANEL_WIDTH, PANEL_HEIGHT / 3);
}
Graphics vImgGraphics = vImg.createGraphics();
vImgGraphics.setColor(Color.WHITE);
vImgGraphics.fillRect(0, 0, PANEL_WIDTH, PANEL_HEIGHT / 3);
drawInfo(vImgGraphics,
PANEL_X,
PANEL_Y,
"Backbuffer",
Color.MAGENTA);
g.drawImage(vImg, 0, PANEL_Y * 2, this);
}
示例2: updateOffscreenImage
import java.awt.image.VolatileImage; //导入依赖的package包/类
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);
}
示例3: render
import java.awt.image.VolatileImage; //导入依赖的package包/类
public void render(){
if(vImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE){
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
Graphics g = vImage.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
g.setColor(Color.WHITE);
/**Draw stuff here*/
graph.render(g);
// g.setColor(Color.GREEN);
// g.drawString("FPS: " + String.valueOf(FPS) , 0, 10);
// g.drawString("UPS: " + String.valueOf(UPS) , 60, 10);
g = canvas.getGraphics();
g.drawImage(vImage, 0, 0, canvasWidth, canvasHeight, null);
g.dispose();
}
示例4: main
import java.awt.image.VolatileImage; //导入依赖的package包/类
public static void main(String[] args) {
BufferedImage src = createSrc();
VolatileImage dst = createDst();
System.out.println("Dst: " + dst);
boolean status;
int count = max_rendering_count;
do {
System.out.println("render image: " + (max_rendering_count - count));
status = render(src, dst);
} while (status && count-- > 0);
if (!status || count > 0) {
throw new RuntimeException("Test failed: " + count);
}
}
示例5: getBufferedImage
import java.awt.image.VolatileImage; //导入依赖的package包/类
protected BufferedImage getBufferedImage(Image img) {
if (img instanceof BufferedImage) {
// Otherwise we expect a BufferedImage to behave as a standard BI
return (BufferedImage)img;
} else if (img instanceof ToolkitImage) {
// This can be null if the image isn't loaded yet.
// This is fine as in that case our caller will return
// as it will only draw a fully loaded image
return ((ToolkitImage)img).getBufferedImage();
} else if (img instanceof VolatileImage) {
// VI needs to make a new BI: this is unavoidable but
// I don't expect VI's to be "huge" in any case.
return ((VolatileImage)img).getSnapshot();
} else {
// may be null or may be some non-standard Image which
// shouldn't happen as Image is implemented by the platform
// not by applications
// If you add a new Image implementation to the platform you
// will need to support it here similarly to VI.
return null;
}
}
示例6: initVI
import java.awt.image.VolatileImage; //导入依赖的package包/类
private static void initVI(GraphicsConfiguration gc) {
int res;
if (destVI == null) {
res = VolatileImage.IMAGE_INCOMPATIBLE;
} else {
res = destVI.validate(gc);
}
if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
if (destVI != null) destVI.flush();
destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
destVI.validate(gc);
res = VolatileImage.IMAGE_RESTORED;
}
if (res == VolatileImage.IMAGE_RESTORED) {
Graphics vig = destVI.getGraphics();
vig.setColor(Color.red);
vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
vig.dispose();
}
}
示例7: render
import java.awt.image.VolatileImage; //导入依赖的package包/类
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());
}
示例8: getAvailableAcceleratedMemory
import java.awt.image.VolatileImage; //导入依赖的package包/类
/**
* Gets the availableAcceleratedMemory attribute of the YassSheet object
*
* @return The availableAcceleratedMemory value
*/
public int getAvailableAcceleratedMemory() {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
try {
GraphicsDevice[] gs = ge.getScreenDevices();
// Get current amount of available memory in bytes for each screen
for (GraphicsDevice g : gs) {
// Workaround; see description
VolatileImage im = g.getDefaultConfiguration()
.createCompatibleVolatileImage(1, 1);
// Retrieve available free accelerated image memory
int bytes = g.getAvailableAcceleratedMemory();
// Release the temporary volatile image
im.flush();
return bytes;
}
} catch (HeadlessException e) {
// Is thrown if there are no screen devices
}
return 0;
}
示例9: paintBackBuffer
import java.awt.image.VolatileImage; //导入依赖的package包/类
/**
* Description of the Method
*
* @param g Description of the Parameter
*/
public void paintBackBuffer(Graphics2D g) {
final int MAX_TRIES = 10;
for (int i = 0; i < MAX_TRIES; i++) {
g.drawImage(backVolImage, 0, 0, this);
if (!backVolImage.contentsLost()) {
return;
}
switch (backVolImage.validate(g.getDeviceConfiguration())) {
case VolatileImage.IMAGE_INCOMPATIBLE:
backVolImage.flush();
backVolImage = g.getDeviceConfiguration().createCompatibleVolatileImage(image.getWidth(), image.getHeight());
case VolatileImage.IMAGE_RESTORED:
Graphics2D gc = backVolImage.createGraphics();
gc.drawImage(image, 0, 0, Color.white, null);
gc.dispose();
break;
}
}
g.drawImage(image, 0, 0, Color.white, null);
}
示例10: createCompatibleVolatileImage
import java.awt.image.VolatileImage; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@Override
public VolatileImage
createCompatibleVolatileImage(int width, int height,
int transparency, int type)
{
if ((type != FBOBJECT && type != TEXTURE)
|| transparency == Transparency.BITMASK
|| type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
示例11: main
import java.awt.image.VolatileImage; //导入依赖的package包/类
public static void main(final String[] args) {
final GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsConfiguration gc =
ge.getDefaultScreenDevice().getDefaultConfiguration();
final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
sg2d.constrain(0, 61, 100, 100);
final AffineTransform expected = sg2d.cloneTransform();
sg2d.setTransform(sg2d.getTransform());
final AffineTransform actual = sg2d.cloneTransform();
sg2d.dispose();
vi.flush();
if (!expected.equals(actual)) {
System.out.println("Expected = " + expected);
System.out.println("Actual = " + actual);
throw new RuntimeException("Wrong transform");
}
}
示例12: test
import java.awt.image.VolatileImage; //导入依赖的package包/类
void test() {
createVImg();
BufferedImage bi = null;
do {
int valCode = vImg.validate(getDefaultGC());
if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) {
createVImg();
}
Graphics2D g = vImg.createGraphics();
draw(g);
bi = vImg.getSnapshot();
} while (vImg.contentsLost());
if (bi != null) {
test(bi);
write(bi);
}
}
示例13: initBackbuffer
import java.awt.image.VolatileImage; //导入依赖的package包/类
private void initBackbuffer() {
createBackbuffer();
int res = bb.validate(getGraphicsConfiguration());
if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
bb = null;
createBackbuffer();
bb.validate(getGraphicsConfiguration());
res = VolatileImage.IMAGE_RESTORED;
}
if (res == VolatileImage.IMAGE_RESTORED) {
Graphics g = bb.getGraphics();
g.setColor(new Color(rnd.nextInt(0x00ffffff)));
g.fillRect(0, 0, bb.getWidth(), bb.getHeight());
volSprite = createVolatileImage(100, 100);
}
volSprite.validate(getGraphicsConfiguration());
}
示例14: accelerateImage
import java.awt.image.VolatileImage; //导入依赖的package包/类
public VolatileImage accelerateImage(BufferedImage bi) {
VolatileImage testVI = f.createVolatileImage(TEST_W, TEST_H);
do {
if (testVI.validate(f.getGraphicsConfiguration()) ==
VolatileImage.IMAGE_INCOMPATIBLE)
{
testVI = f.createVolatileImage(TEST_W, TEST_H);
}
Graphics2D g = testVI.createGraphics();
g.setComposite(AlphaComposite.Src);
g.setColor(Color.green);
g.fillRect(0, 0, TEST_W, TEST_H);
g.drawImage(bi, 0, 0, null);
g.drawImage(bi, 0, 0, null);
g.drawImage(bi, 0, 0, null);
g.dispose();
} while (testVI.contentsLost());
return testVI;
}
示例15: main
import java.awt.image.VolatileImage; //导入依赖的package包/类
public static void main(String[] args) {
boolean iaeThrown = false;
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().
getDefaultConfiguration();
try {
VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0);
} catch (IllegalArgumentException iae) {
iaeThrown = true;
}
if (!iaeThrown) {
throw new RuntimeException ("IllegalArgumentException not thrown " +
"for createCompatibleVolatileImage(0,0)");
}
}