gpt4 book ai didi

Java:OutOfMemory 使用 Robot#createScreenCapture(Rectangle)

转载 作者:行者123 更新时间:2023-11-30 09:42:03 25 4
gpt4 key购买 nike

我正在编写一个以设定的时间间隔捕获屏幕的程序,当我开始测试时,我发现在它开始捕获图片后几乎立即出现了 OutOfMemoryException。我尝试分配更多内存 - 我给了它 256m,但这几乎没有帮助。它所做的只是让它在抛出异常并再次崩溃之前再持续 2 或 3 秒。

我知道 createScreenCapture(...) 方法使用大量内存,但我看到示例程序可以使用相同的方法记录很长时间 - 它们是如何做到的?

编辑:我采纳了你们的一些建议,现在我没有得到 OutOfMemoryExceptions!万岁!我采取了将照片保存到硬盘驱动器的方法。然而,实际将它们写入存档文件确实需要相当长的时间。将 63 帧写入存档文件几乎需要 2 分钟!

我无法提供任何代码,因为我正在重写 I/O 部分。致力于改善 ^ 情况。

最佳答案

I have seen example programs that can record for long amount of times using the same method - how do they do it?

将图像序列化到磁盘(作为单独的文件或放入单个 Zip)。


Is there a certain procedure I should use for saving it on a hard drive? I was thinking of converting images into an int[] array and then just storing that, since arrays are serializable.

可以采用多种策略。

  • 将图像转换为无损(且易于编码)图像格式并存储图像:
    1. 在磁盘上的单独文件中,或者..
    2. 作为(未压缩的)Zip 存档中的单独条目。通过使用 Zip,我们可以解决早期报告的存储“数千”个文件的问题。考虑到速度(事实上 Zip 对大多数媒体格式的作用很小),请将其解压缩。
  • 我曾经在 usenet 上看到名为 (AFAIR)“Screenies”或类似名称(现在找不到)的代码,它的功能与您建议的非常相似。它将原始信息(没有任何编码)存储到磁盘上。我尝试了代码,但无法获得比将图像编码为 PNG 并将图像序列化到磁盘更好的性能。您可能想运行一些测试,看看现在哪种方法效果更快。

关于Java:OutOfMemory 使用 Robot#createScreenCapture(Rectangle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8782396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com