3

I am new to image processing in java .
I was given a task to re-size and scale images image of a web site

Is there a simple Library that will do this task?
a library where i have to download a jar - added to my project ?
I prefer not to be forced to install codecs and files to the windows.

I need the library to support only the basic functions

Lib.cropImage();
Lib.resizImage();
Lib.scaleImage()

I already found a library called JAI but I can't find the jar to download it.
Am I missing something ?

oers
  • 18,436
  • 13
  • 66
  • 75
A.Alqadomi
  • 1,529
  • 3
  • 25
  • 33
  • Something like [this](http://stackoverflow.com/questions/244164/resize-an-image-in-java-any-open-source-library)? – wallenborn Nov 29 '11 at 12:39

5 Answers5

3

You can use the standard Image class part of Java libraries. Scaling images should be fairly easy by using Image.getScaledInstance(int width, int height, int hints)

GETah
  • 20,922
  • 7
  • 61
  • 103
  • thanks for the answer but when i use this function iam unable to save it to the Disc Image img = null; img = ImageIO.read(new File("D:/files/save/Penguins_1321871576590.jpg")); img.getScaledInstance(50, 50, Image.SCALE_SMOOTH); how can i save it to the hard drive since the Image has no method to do that ? am I forced to convert it to buffered Image and then save it Using ImageIO ? or there is easier way ? – A.Alqadomi Nov 29 '11 at 13:10
  • Hi, glad it helped. That is a different question, please accept this answer if it resolved the original question and post a new one about saving a scaled image into disk :). Please post the link here as well so that I can follow up with it :) – GETah Nov 29 '11 at 14:05
3

For cropping, use BufferedImage.getSubimage() (see this StackOverflow Q&A for more details). For resizing, use Graphics.drawImage() (see this StackOverflow answer for more details). And for scaling, use Image.getScaledInstance().

Other options are:

Community
  • 1
  • 1
Go Dan
  • 15,194
  • 6
  • 41
  • 65
1

The Java2D library ought to be sufficient enough.

mre
  • 43,520
  • 33
  • 120
  • 170
0

For image processing puroses I would recommend a package from the following list.

In your case JAI would do the job, and you can download it here.

Matyas
  • 13,473
  • 3
  • 60
  • 73
0

Have you tried imageJ which boasts to be world's fastest pure Java image processing program

David
  • 19,577
  • 28
  • 108
  • 128