0

我正在使用它来设置缓冲图像的大小。

Dimension imgDim = new Dimension(700, 380);

BufferedImage gridImage = new BufferedImage(imgDim.width, imgDim.height,
    BufferedImage.TYPE_INT_RGB);

而不是这个,我想使用类似的东西来设置图像的大小:

Dimension imgDim = d;

BufferedImage gridImage = new BufferedImage(d.width/8, d.height/8,
    BufferedImage.TYPE_INT_RGB);

但我得到negativeArraySizeException

d是我JFrame使用getMaximumSize()方法得到的尺寸

当我打印出d.width/8我无法理解的 268435455 之类的值时。有没有其他方法可以做到这一点,请帮忙

谢谢

4

2 回答 2

1

d is the dimensions of my JFrame which I'm getting using getMaximumSize() method

You would get d using the getSize() method after you call the pack() method or setSize() method.

于 2013-04-16T17:20:51.803 回答
0

You should use getSize() instead of getMaximumSize().

If you don't setPreferredSize for your JFrame, getMaximumSize() will return a very big number. See Component.getMaximumSize()

getSize() returns your JFrame's current size

See Component JavaDocs

于 2013-04-16T17:20:23.430 回答