Java Robot createScreenCapture性能 [英] Java Robot createScreenCapture performance

查看:1095
本文介绍了Java Robot createScreenCapture性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要抓取一系列截图并将它们连接成电影。我正在尝试使用java Robot类来捕获屏幕。

I need to grab a series of screenshots and concatenate them into a movie. I'm trying to use the java Robot class to capture the screen.

但是我的机器上的createScreenCapture()方法需要1秒多的时间。我甚至无法获得1 fps。有没有办法加快速度?或者还有其他API吗?

But the createScreenCapture() method takes more than 1 second on my machine. I can't even get 1 fps. Is there a way to speed it up? Or is there any other API?

编辑:它正在分配一个缓冲的图像。

It is allocating a buffered image.

BufferedImage image = robot .createScreenCapture(屏幕);
//将屏幕截图保存为jpg

文件文件=新文件(images / screen+ index +.jpg);

ImageIO.write( image,jpg,file);
index ++;

BufferedImage image = robot.createScreenCapture(screen); //Save the screenshot as a jpg
File file = new File("images/screen"+ index + ".jpg");
ImageIO.write(image, "jpg", file); index++;

将其写入jpg文件需要大约200 ms,因为获取BufferedImage需要大约1400ms。

Writing it to the jpg file takes about 200 ms where as getting BufferedImage takes about 1400ms.

推荐答案

尝试尝试不同的屏幕设置。颜色深度会影响它,因为AWT必须将所有内容转换为常见的栅格格式。

Try experimenting with different screen settings. The colour depth will affect it as AWT has to convert everything to a common raster format.

我的电脑的一些示例时间:

Some example timings from my PC:

 Resolution | Depth | Time taken 
------------+-------+------------
 1280x1024  | 32    | 215ms
 1280x1024  | 16    | 155ms
 1600x900   | 32    | 235ms

我的适配器不能做24bpp或64bpp所以我无法测试那些深度,但我会猜测他们需要更多的CPU周期来转换。

My adapter cannot do 24bpp or 64bpp so I was unable to test with those depths, but I would guess that they would require more CPU cycles to convert.

这篇关于Java Robot createScreenCapture性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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