gpt4 book ai didi

Java全屏截图

转载 作者:搜寻专家 更新时间:2023-10-31 20:30:11 25 4
gpt4 key购买 nike

我正在开发一个游戏项目,我已经编写了一些允许游戏全屏运行的基本代码。

我的问题是,当游戏处于全屏模式时,我无法按 Prnt Scrn 截取屏幕截图!如果我尝试截取屏幕截图,它只会截取全屏游戏窗口后面的任何内容。知道为什么这不起作用吗?

我在 Windows 7 上运行。这是说明我的问题的 SSCCE:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FullscreenScreenShotSSCCE extends JFrame
{
private JPanel screenP;

private GraphicsDevice grDev;

/**
* Constructor
* Preconditions: None.
* Postconditions: The window for the SSCCE is created.
**/

public FullscreenScreenShotSSCCE()
{
super("Fullscreen Prnt Scrn problem SSCCE");
int screenX = 640;
int screenY = 480;
this.setSize(screenX,screenY);

// set up resolution change mode

grDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // obtains your graphics device

// setup the game for full-screen if requested.

System.out.println("Trying to start program in Fullscreen mode.");

if(grDev.isFullScreenSupported()) // makes sure fullscreen is supported before doing anything.
{
System.out.println("FullScreen is supported");
this.setUndecorated(true);
DisplayMode resChangeMode = new DisplayMode(640,480,32,DisplayMode.REFRESH_RATE_UNKNOWN); // create new DisplayMode with different resolution.

try
{
grDev.setFullScreenWindow(this); // set fullscreen mode on. Otherwise this won't work
grDev.setDisplayMode(resChangeMode); // change DisplayMode to our new resolution.
System.out.println("Change resolution: Success!");
}
catch(Exception e)
{
System.out.println("Change resolution: FAIL!");
}
}
this.setExtendedState(MAXIMIZED_BOTH);

// instantiate main panel

screenP = new SSCCEPanel();
this.add(screenP);

// finishing touches on Game window

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);

System.out.println("Game Window successfully created!!!");
}


public static void main(String[] args)
{
FullscreenScreenShotSSCCE gui = new FullscreenScreenShotSSCCE();
}
}




/**
* SSCCEPanel is the JPanel that manages the example's timer, painting, and logic.
**/

class SSCCEPanel extends JPanel
{
private Timer timer;
public double prevFPS;
boolean timerReady;

// The SoundPlayer object is used by the example to play the sounds.

public SSCCEPanel()
{
super(true);
}

/**
* repaints the SSCCE.
* This just shows the current FPS and the number of sounds currently playing.
**/

public void paintComponent(Graphics g)
{
super.paintComponent(g);

Graphics2D g2D = (Graphics2D) g;
g2D.setColor(new Color(0x000000));
g2D.drawString("Java fullscreen!", 20,20);
g2D.drawString("Try to take a screenshot!", 20,40);
g.dispose();
}
}

最佳答案

尝试 Alt-PrintScreen(捕获当前窗口)。这可能会在全屏独占模式下起作用。祝你好运:-)

关于Java全屏截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9420154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com