问题
I am having trouble implementing a game pause blur screen to render during the gamepause state. I need to take a picture or texture of the current screen i.e gamerunning state, just when the user pauses the screen . Maybe store it to memory, blur it then render it to screen to achieve a nice blur, Gaussian blur effect like they do in popular games like Angry birds.
I tried implementing using a screenshot, but the process of screen capture makes the game freeze for a few seconds which is not nice.
Here is part of my render code
private void updatePlayerForUserInput(float delta)
{
if (Gdx.input.isKeyPressed(Keys.P) || pause)
{
ScreenShotSaver.saveScreenShot();
state = State.GAME_PAUSED;
if(!DEBUG_MODE)
{
toggleGestureProcessor(false);
setBackgroundTexture(new TextureRegion(applyBlurEffect(Gdx.files.external("madboy/screenshot.png"))));
gameScreenGamePauseMenu.sendInMenu();
}
}
}
Can someone help implement s screen like this

This is an example of the effect I desire greatly 1 :enter link description here This is another one, similar thing though 2:enter link description here
This is a part of my update logic depending on game state
private void render(float delta)
{
switch (state)
{
case GAME_READY:
renderReady();
break;
case GAME_RUNNING:
renderRunning(delta);
break;
case GAME_PAUSED:
renderPaused();
break;
case GAME_LEVEL_END:
renderLevelEnd();
break;
case GAME_OVER:
renderGameOver();
break;
}
}
private void update(float delta)
{
switch(state)
{
case GAME_READY:
updateReady();
break;
case GAME_RUNNING:
updateRunning(delta);
break;
case GAME_PAUSED:
updatePaused();
break;
case GAME_LEVEL_END:
updateLevelEnd();
break;
case GAME_OVER:
updateGameOver();
break;
}
}
Iam using Libgdx library and programming in java
回答1:
Instead of saving the image of the screenshot to a file, try using the following
TextureRegion(Texture)
Texture(Pixmap)
Pixmap(byte[], int, int)
The byte array in Pixmap's constructor should contain the image bytes, the two ints are offset and length
Example of how you could get the image as bytes:
BufferedImage bufferedImage = new Robot().createScreenCapture(new Rectangle(startX, startY, width, height));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, format, outputStream);
outputStream.flush();
byte[] data = outputStream.toByteArray();
outputStream.close();
Where format
can be any image format in the form of a String (example below):
String format = "png";
String format = "jpg";
来源:https://stackoverflow.com/questions/29051437/copy-a-picture-of-the-current-screen-just-before-game-pause-blur-it-and-render-t