Windows 8 OS中的屏幕截图捕获 [英] Screenshot capture in Window 8 OS

查看:264
本文介绍了Windows 8 OS中的屏幕截图捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要捕获我的Java应用程序中的屏幕截图,我编写了以下代码

To capture screen shot in my java application i have write following code

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

BufferedImage capture = new Robot().createScreenCapture(screenRect);

ImageIO.write(capture, "png", new File("resources/img/screenshot.png"));

此操作成功并捕获了屏幕快照,但在Windows 8操作系统中不起作用.还有其他人遇到这种类型的问题并得到解决吗?

This is working successfully and capture screen shot but this is not working in windows 8 operating system. any one else who have face this type of problem and get soluction?

推荐答案

您可以执行以下操作,而无需使用以下代码在本地计算机中写入文件

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

这篇关于Windows 8 OS中的屏幕截图捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆