Re: Determining image bounds of image created in code
Aaron wrote:
On Jun 29, 9:08 pm, "Jarrick Chagma" <jarr...@large.com> wrote:
"Aaron" <aaron.james.g...@gmail.com> wrote in message
news:80fa6897-f483-40f6-9e97-255d9fd10eef@l12g2000yqo.googlegroups.com...
I have written code which creates an image on a JPanel (inside a
JFrame) and saves it as a jpeg.
Each image is a different size, so I need to manually resize the
JFrame to the bounds of the image before saving (else the whole image
isn't saved).
I would like to be able to determine the bounds of the image in code,
so this manual resizing is not needed.
How would I go about acheiving this?
Thanks in Advance.
I am a bit confused. All images implement getWidth() and getHeight()
methods. Is there a reason why you cannot use those?
The image includes a lot of text. I override the paintComponent
method, and use the drawX methods on the Graphics2D object.
If I create an image by say creating a BufferedImage, the size is
taken in the constructor.
Basically in a nutshell I suppose I want to crop the image, or resize
the JPanel to fit the image, with no excess...
Is that any clearer?
BufferedImage has a method to get a sub-image so assuming you know how
big it is, that shouldn't be a problem. If you then want do draw that
image onto a JPanel and you want the full JPanel displayed in your
JFrame, you need to set the preferred size of the JPanel to the size of
your image and call pack() on the JFrame. You also might just be able
to call validate() but I'd have to try that.
But it still isn't 100% clear that that is what you want. You might try
again by explaining it from the beginning.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access