user2224555
user2224555

Reputation: 15

Dynamically set the size of buffered image

I'm using this to set the size of my buffered image.

Dimension imgDim = new Dimension(700, 380);

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

instead of this, I would like to set the size of the image using something like:

Dimension imgDim = d;

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

but I'm getting negativeArraySizeException

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

when I print out the value of d.width/8 its something like 268435455 which I can't make sense of. Is there another way to do this please help

Thank you

Upvotes: 0

Views: 2543

Answers (2)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

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.

Upvotes: 1

Aboutblank
Aboutblank

Reputation: 717

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

Upvotes: 0

Related Questions