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
Post a Comment