-2

Is there any way to resize image uploaded to server? I have uploaded a image using servlet and JSP. Now I want to resize that image according to fixed ratio.

Is there any API available?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user2320220
  • 17
  • 2
  • 5

2 Answers2

0
Image newimg = img.getScaledInstance(scale, scale,
            java.awt.Image.SCALE_SMOOTH);
Jonas Eicher
  • 1,413
  • 12
  • 18
  • 1
    FYI You might to take a read of [The Perils of Image.getScaledInstance()](https://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html) – MadProgrammer May 08 '13 at 10:01
  • I am just using getScaledInstance to statically initialize tiny icons, so I never noticed the performance issues. Nice, in-depth article though! – Jonas Eicher May 13 '13 at 15:37
-2

Quoting from http://www.mkyong.com/java/how-to-resize-an-image-in-java/

Graphics2D is providing the image re-size feature as follows :

BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
Dharman
  • 30,962
  • 25
  • 85
  • 135
Janny
  • 681
  • 1
  • 8
  • 33