X

Geertjan's Blog

  • March 26, 2008

Resizing Images in NetBeans IDE

Geertjan Wielenga
Product Manager
Small(ish) but annoying pet peeve of mine: I need an image for an application that I'm coding in NetBeans IDE. I go on-line and find the image that I need. I right-click the image on-line and save it right there, from my browser, into my application's source structure.

Then... dang! I open the image in the IDE and see that... its size is not what I would want it to be. So... I need to go outside the IDE (where it is cold, cold, cold) and change the image size there. Why? Because when you open the image in the IDE, you can only zoom. Not resize.

So, I've added a "Resize" menu item on image nodes in the explorer views:

When the menu item is selected, the image opens in a new dialog, which should be a TopComponent at some point, where you can resize the image (thanks to the Visual Library):

When you click OK, a new image is created (so, no worries, nothing will happen to your original image), in the same place as the old one, with a new name, consisting of the original name, plus the dimensions of your new image.

It is not perfect yet, but it is definitely already usable in most cases:

http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=6726

If your original image is very large and you want to make it smaller, you'll have problems, because the original image and the image you're resizing will overlap. As the image you're resizing gets smaller, you won't be able to see it anymore because the original image will cover it. Need to fix that. It works better if you want to make the image larger than the original.

The latest version of the plugin (1.2) includes antialiasing, but the quality of the image will definitely decrease as you increase its size. Advice on this point is very welcome.

Join the discussion

Comments ( 9 )
  • Seapegasus Wednesday, March 26, 2008

    I assume this requires NetBeans to run with JDK6? Because for me it complains about GroupLayout missing. Unfortunately there is no 'real' JDK 6 for Mac OS.


  • Geertjan Wednesday, March 26, 2008

    Yup. Makes sense. I'm sorry -- but then again, you should be complaining to Apple and not to me. :-) Anyway, I will see if I can get it working on JDK 5, especially for our Mac friends.


  • Seapegasus Wednesday, March 26, 2008

    Wasn't a complaint, rather a resignated statement. :-D

    There is a well-hidden advanced setting for the GUI builder where you can switch the builder to generate code with JDK5 in mind. You still have to recreate the window though, it guess it doesn't convert existing ones.


  • Robert Wednesday, March 26, 2008

    Yes, it can regenerate the window code when you change the generation mode. The property to change is on the Form object at the top of the inspector hierarchy, it is called "Layout Generation" and you can change it to "Swing Layout Extension Library" to generate code using the pre-Java6 GroupLayout.

    When we migrated all our Swing code to Java 6 we needed to do this on each form, An option to change it to all forms in a project will be nice (at least we did not find it)


  • Tonny Kohar Wednesday, March 26, 2008

    Regarding the resize image quality, for raster image there always quality change due to its pixel based nature. However, there are a few resample algorithm that could help to improve the quality and Java also come with 3 of them:

    - RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR

    - RenderingHints.VALUE_INTERPOLATION_BILINEAR

    - RenderingHints.VALUE_INTERPOLATION_BICUBIC

    Depending on the type of image eg: a lot of solid color (graph, chart, etc) or photo, different algorithm produce different result.

    Basically (it is not a rule, always test with different algorithm for best result)

    - Nearest Neighbor is good for a lot of solid color eg: chart, simple logo, etc

    - Bilinear is good for images having horizontal or vertical lines and large block of solid color eg: web button

    - Bicubic is general purpose resample algorithm using average surrounding pixel calculation eg: photo

    Sample Java code:

    BufferedImage scaledImage = new BufferedImage(w,h,type);

    Graphics2D g2 = scaledImage.createGraphics();

    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC );

    g2.drawImage(img,0,0,w,h,null);

    g2.dispose();


  • Geertjan Wednesday, March 26, 2008

    Thanks Robert, I took those steps and uploaded version 1.3 of the plugin that resulted from that. So Mac users should now be able to use the plugin too. Thanks also Tonny, will investigate those.


  • Tonny Kohar Thursday, March 27, 2008

    Another note regarding resizing image, you might be interested to read "The Perils of Image.getScaledInstance()" by Chris Campbell at http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html


  • Seapegasus Thursday, March 27, 2008

    Thanks for updating the plugin, it now runs on MacOS with JDK5 too!


  • guest Monday, May 5, 2008

    ure


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.