[英]Screenshot capture in Window 8 OS
To capture screen shot in my java application i have write following code为了在我的 Java 应用程序中捕获屏幕截图,我编写了以下代码
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "png", new File("resources/img/screenshot.png"));
This is working successfully and capture screen shot but this is not working in windows 8 operating system.这工作成功并捕获屏幕截图,但这在 Windows 8 操作系统中不起作用。 any one else who have face this type of problem and get soluction?
还有谁遇到过这种类型的问题并获得解决方案?
my application is install into the program file folder and the windows 8 not give permission to write there how i can write there now?
我的应用程序安装到程序文件夹中,而 Windows 8 不允许在那里写入,我现在如何写入?
Do not write it there!不要把它写在那里! OS manufacturers as well as Sun/Oracle have been saying for years not to write files to the application's installation directory.
操作系统制造商以及 Sun/Oracle 多年来一直在说不要将文件写入应用程序的安装目录。 It is not only the wrong place to write them, but as you have discovered, does not provide write permissions for a typical Java app.
它不仅是编写它们的错误位置,而且正如您发现的那样,它不为典型的 Java 应用程序提供写入权限。
Instead put the screen-shot in user.home
eg as seen in this answer .而是将屏幕截图放在
user.home
例如在这个答案中看到的。
you can do that without writing file in your local machine by using the following code您可以使用以下代码在本地计算机中不写入文件的情况下执行此操作
ByteArrayOutputStream bos=new ByteArrayOutputStream();
byte[] imageByte = null;
try
{
//To Get the the size of the screen.
Rectangle screenRect = new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize());
//To Store the scrreen shot in buffer.
BufferedImage capture = new Robot()
.createScreenCapture(screenRect);
//To Save the image on specific location.
ImageIO.write(capture, "png",bos);
bos.flush();
imageByte=bos.toByteArray();
bos.close();
// File file = new File("resources/img/screenshot.png");
MultipartEntity mpEntity = new MultipartEntity();
// ContentBody cfBody = new FileBody(file);
ContentBody cfBody = new ByteArrayBody(imageByte,"screenshot.png");
mpEntity.addPart("screenshot", cfBody);
} }
send direct the byte array in plase of the image直接发送字节数组代替图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.