-3

Am having some pictures with large resolution like 4000x3000 . I want to create a java program which can re size the image size to something small like 1000x900 just for an example . Can anyone tell me some particular java library which can help me to achieve this task . It would be really helpful if you can post any link to such kind of tutorial .

Nitin Khola
  • 129
  • 2
  • 8
  • 2
    see this answer http://stackoverflow.com/questions/603283/what-is-the-best-java-image-processing-library-approach – notXX Jan 22 '13 at 07:20
  • You can check [this](http://stackoverflow.com/questions/11959758/java-maintaining-aspect-ratio-of-jpanel-background-image/11959928#11959928) as well – MadProgrammer Jan 22 '13 at 08:05

3 Answers3

1

Please try to Google before submitting a post over here ... http://www.mkyong.com/java/how-to-resize-an-image-in-java/, a simple Google will provide you with abundant of resulst, if those doesn't fit your need then you can try asking here.

Ewe Seong
  • 67
  • 6
  • 1
    thanks Ewe Seong , yes it was exactly what i was looking for . Next time i would surely search on google before posting a question here :) – Nitin Khola Jan 22 '13 at 08:36
1

java.awt.Image.getScaledInstance can do that. But more reliable and faster approach is here: http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html

Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
1

You can get it calling this method that uses Java native classes:

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
...

public static BufferedImage resizeImage(Image originalImage, int newWidth, int newHeight) {
    BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = resizedImage.createGraphics();

    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.drawImage(originalImage, 0, 0, newWidth, newHeight, this);
    g.dispose();
    return resizedImage;
}

There are many image types (BINARY, GRAY, RGB, BGR, ARGB, ABGR...). You can choose one (as I did selecting BufferedImage.TYPE_INT_ARGB), or declare this value as a parameter. Just have a quick look to BufferedImage class for details.

arutaku
  • 5,937
  • 1
  • 24
  • 38