Image Resizing, Java -


could explain why line of code isn't working. no errors given. doesn't resize image.

image = imageio.read(file);  image.getscaledinstance(imagedisplaybox.getwidth(), imagedisplaybox.getheight()); imagedisplaybox.seticon(new imageicon(image)); 

i've looked @ other answers on stackoverflow , noticed lot of people using .getscaledinstance method.

i (think) might fact have .seticon - although i'm not best java.

the image printed displays top left of image due size.

you're ignoring returned value. want:

image = image.getscaledinstance(imagedisplaybox.getwidth(),                                 imagedisplaybox.getheight(), 5); 

or maybe make things clearer:

image scaled = image.getscaledinstance(imagedisplaybox.getwidth(),                                        imagedisplaybox.getheight(), 5); imagedisplaybox.seticon(new imageicon(scaled)); 

from the docs:

creates scaled version of image. new image object returned render image @ specified width , height default. new image object may loaded asynchronously if original source image has been loaded completely.

note that doesn't changing existing image. creates new image given size.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -