Forums Register Login

Crop an Image

+Pie Number of slices to send: Send
I have an image which original size is 125px wide and 150px tall. I am setting this image into the bean for web service purpose. But I wanted to crop the original image to a size of 80px wide and 80px tall before I set it to the bean. I would appreciate if someone can suggest me how if it is possible and how would I able to do that. Thank you very much.

Here is the code how I am setting the Image into the bean:

+Pie Number of slices to send: Send
Try using the read() and write() methods of the javax.imageio.ImageIO class, along with the getScaledInstance() method of the java.awt.Image class.
+Pie Number of slices to send: Send
I am wondering if you could provide a sample for that. I would really appreciate that. Thanks!!
+Pie Number of slices to send: Send
Something like this (though I couldn't get it to output a JPEG thumbnail, only a PNG thumbnail)

+Pie Number of slices to send: Send
You may wish to read The Perils of Image.getScaledInstance(), though.
+Pie Number of slices to send: Send
Do you want to crop or scale? They're not the same thing. How are you acquiring the image, any guarantee it's in a compatible format for the system? That can have a HUGE impact on the performance of things like drawImage.
+Pie Number of slices to send: Send
Its not clear to me if you want to just crop or scale one image, or to programatically scale or crop lots of images in your Java application.

If its the former, I'd suggest you use something like The Gimp, or one of the web services Flikr/Picassa that support simple photo editing.
+Pie Number of slices to send: Send
Thanks for the link Lester. I didn't know that Image.getScaledInstance() was so outdated!
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1504 times.
Similar Threads
Crop an image in Java
How to crop image in java
How can I split an Image ?
several animation frames in one file, transparency issues
Resizing Image: Java vs PHP
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:02:45.