博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java截全屏_Java全屏截图
阅读量:6376 次
发布时间:2019-06-23

本文共 2549 字,大约阅读时间需要 8 分钟。

我正在开发一个游戏项目,并且我编写了一些基本代码,允许游戏全屏运行.

我的问题是,当游戏处于全屏模式时,我无法按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(捕获当前窗口).这可以在全屏独占模式下完成.祝好运:-)

转载地址:http://mlvqa.baihongyu.com/

你可能感兴趣的文章
流水落花春去也
查看>>
从.NET中委托写法的演变谈开去(下):性能相关
查看>>
C# 多人聊天程序
查看>>
【教训】为什么不作备份?!
查看>>
网搜索引擎架构设计
查看>>
iOS笔记:内存管理
查看>>
python开发_python中str.format()
查看>>
HTML5, CSS3, ES5新的web标准和浏览器支持一览 转
查看>>
ThinkPHP3.0启动过程
查看>>
【leetcode】Longest Common Prefix (easy)
查看>>
JAX-WS(JWS)发布WebService
查看>>
Centos7安装docker-compse踩过的坑
查看>>
细说Nullable<T>类型
查看>>
oracle 插入表数据的4种方式
查看>>
7.Ajax
查看>>
Linux vi/vim编辑器常用命令与用法总结
查看>>
对于 url encode decode js 和 c# 有差异
查看>>
centos rz sz安装
查看>>
mysql 修改列为not null报错Invalid use of NULL value
查看>>
epoll源码分析
查看>>