java截全屏_Java全屏截图
我正在開發一個游戲項目,并且我編寫了一些基本代碼,允許游戲全屏運行.
我的問題是,當游戲處于全屏模式時,我無法按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截全屏_Java全屏截图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《操作系统》逻辑地址如何转换为物理地址
- 下一篇: java美元兑换,(Java实现) 美元