本文整理匯總了Java中java.awt.image.BufferStrategy.contentsRestored方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferStrategy.contentsRestored方法的具體用法?Java BufferStrategy.contentsRestored怎麽用?Java BufferStrategy.contentsRestored使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.BufferStrategy
的用法示例。
在下文中一共展示了BufferStrategy.contentsRestored方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import java.awt.image.BufferStrategy; //導入方法依賴的package包/類
/**
* Render offscreen graphics into the frame.
*/
private void render() {
final BufferStrategy bufferStrategy = frame.getBufferStrategy();
do {
do {
final Graphics2D graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
// canvas is not opaque, so fill with background color
graphics.setPaint(background);
graphics.fillRect(0, 0, 400, 400);
// then let canvas render into graphics
canvas.render(graphics);
graphics.dispose();
} while (bufferStrategy.contentsRestored());
bufferStrategy.show();
} while (bufferStrategy.contentsLost());
}
示例2: render
import java.awt.image.BufferStrategy; //導入方法依賴的package包/類
public void render() {
ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
BufferCapabilities bufCap =
new BufferCapabilities(imgFrontBufCap,
imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
try {
createBufferStrategy(2, bufCap);
} catch (AWTException ex) {
createBufferStrategy(2);
}
BufferStrategy bs = getBufferStrategy();
do {
Graphics g = bs.getDrawGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.red);
g.drawString("Rendering test", 20, 20);
g.drawImage(bi, 50, 50, null);
g.dispose();
bs.show();
} while (bs.contentsLost()||bs.contentsRestored());
}
示例3: draw
import java.awt.image.BufferStrategy; //導入方法依賴的package包/類
/** Draws every character of every row onto the canvas. */
public void draw() {
final BufferStrategy bs = this.getBufferStrategy();
do {
do {
final Graphics2D gc;
try {
gc = (Graphics2D) bs.getDrawGraphics();
} catch (final NullPointerException | IllegalStateException e) {
// BufferStrategy may not have been created on the first call,
// so just do a recursive call until it works.
// This may be a bad idea.
draw();
return;
}
gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
gc.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
gc.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gc.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
// Font characters are pre-rendered images, so no need for AA.
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
// No-need for text rendering related options.
gc.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
gc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
// If alpha is used in the character images, we want computations related to drawing them to be fast.
gc.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
screen.draw(gc, imageCache);
gc.dispose();
} while (bs.contentsRestored()); // Repeat render if drawing buffer contents were restored.
bs.show();
} while (bs.contentsLost()); // Repeat render if drawing buffer was lost.
}
示例4: drawScene
import java.awt.image.BufferStrategy; //導入方法依賴的package包/類
@Override
public void drawScene(Snowflake[] scene, ScreenParameters screenParameters) {
if (DEBUG_SHOW_FPS) fpsCounter.recordFrame();
BufferStrategy strategy = getBufferStrategy();
do {
do {
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
SnowFlake3DRenderer snowFlake3DRenderer = new AwtSnowflakeRenderer(g2d, screenParameters);
drawBackground(g2d, screenParameters);
for (Snowflake snowflake : scene) {
snowFlake3DRenderer.renderSnowflake(snowflake.x + xoffset, snowflake.y, snowflake.size, snowflake.z, screenParameters);
}
if (DEBUG_SHOW_FPS) {
g2d.setColor(Color.white);
g2d.drawString(String.format("%.2f min FPS", fpsCounter.getMinFps()), 20, 20);
g2d.drawString(String.format("%.2f max FPS", fpsCounter.getMaxFps()), 20, 35);
}
g2d.dispose();
} while (strategy.contentsRestored());
strategy.show();
DEFAULT_TOOLKIT.sync(); // Seems like this is necessary on Ubuntu for smooth animation
} while (strategy.contentsLost());
}
示例5: doUpdate
import java.awt.image.BufferStrategy; //導入方法依賴的package包/類
private void doUpdate() {
BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
do {
do {
Graphics graphics = bufferStrategy.getDrawGraphics();
graphics.dispose();
} while(bufferStrategy.contentsRestored());
bufferStrategy.show();
} while(bufferStrategy.contentsLost());
}
示例6: doProcess
import java.awt.image.BufferStrategy; //導入方法依賴的package包/類
private void doProcess() {
long elapsedTime = System.currentTimeMillis() - currentTime;
currentTime += elapsedTime;
BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
int width = jFrame.getWidth();
int height = jFrame.getHeight();
do {
do {
Graphics graphics = null;
try {
graphics = bufferStrategy.getDrawGraphics();
} catch(IllegalStateException | NullPointerException e) {
}
if(graphics == null) {
return;
}
Graphics2D graphics2D = Graphics2D.class.cast(graphics);
if(Constants.isRenderingInRealtime()) {
graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
} else {
graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
}
graphics2D.clearRect(0, 0, width, height);
graphics2D.drawImage(bufferedImage, 0, 0, width, height, null);
graphics2D.setColor(Color.WHITE);
graphics2D.drawString("FPS " + newFPS, 20, 70);
graphics2D.dispose();
} while(bufferStrategy.contentsRestored());
bufferStrategy.show();
} while(bufferStrategy.contentsLost());
Toolkit.getDefaultToolkit().sync();
this.elapsedTime += elapsedTime;
oldFPS++;
if(this.elapsedTime >= 1000L) {
this.elapsedTime -= 1000L;
newFPS = oldFPS;
oldFPS = 0;
}
}