我在截取屏幕截图时遇到问题。这是我的测试代码。
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Dimension;
public class Test {
public static void main(String[] args) throws AWTException {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int[] pixels = new int[(int) (screenSize.getWidth() * screenSize.getHeight()) * 3];
Robot robot = new Robot();
int i = 0;
while (true) {
robot.createScreenCapture(new Rectangle(screenSize))
.getRaster().getPixels(0, 0, (int) screenSize.getWidth(), (int) screenSize.getHeight(), pixels);
System.out.println(++i);
}
}
}
在我的 Mac*s* 上,使用 OS X 10.6.4 和 Java 1.6.0_20-b02-279-10M3065,两次迭代后失败。它似乎在 Windows 上运行良好。你能重现这种行为吗?
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at apple.awt.CRobot.getRGBPixels(CRobot.java:204) at java.awt.Robot.createScreenCapture(Robot.java:329) at Test.main(Test.java:16)
最佳答案
OutOfMemory 意味着您需要give the program more memory 。如今,这种情况在 Mac 上更常见,因为 Java 现在是 64 位,并且需要更大的堆。
关于java - 可能的 Apple JVM 错误 : java. lang.OutOfMemoryError : Java heap space at apple. awt.CRobot.getRGBPixels(CRobot.java:204),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3871530/