I am looking for a java library that can scale, crop images without losing much quality, convert between image formats (png<->jpg), etc.
There is a similar question already, but it was asked 1,5 years ago and I am hoping maybe there are any new inventions, as everything mentioned there looks outdated (and scary).
I had good results with ImageMagick for typical work on gifs and jpgs.
Take a look at the Java Advanced Imaging library.
Related
I'm working on developing a media player like application in Java (it's a swing based application) and I want it to be able to run on smoothly using as many different file formats as possible. I want to be able to take in a bunch of music files, then retrieve their tag information (artist/album/songname/etc), and then later play them. I've done a bit of poking around but it's hard to find a library which will support .m4a, .mp3. and maybe even .flac files. Does anyone know of a library which will do what I want? Thanks!
JMF is, to put it in the nicest possible way, rather out of date, unmaintained, difficult to distribute and in my experience has quite a few annoying bugs that crop up where you least expect them. And if you can get FMJ to work at all, good luck - they pride on it being an up to date, drop in replacement but my experience begs to differ on both those points.
Personally I wouldn't even consider it - just use separate libraries for each format or bunch of formats you want to support. JLayer would be a good one to start with as it can do a fair few, JFlac will do your flac files on top of that.
There's JMF - see http://en.wikipedia.org/wiki/Java_Media_Framework, which also lists some alternatives. I've had rather mixed success with JMF; it worked well for some static MPEG files but didn't seem compatible with the streaming sources we were using at the time (a couple of years ago).
An alternative to jFLAC for FLAC files is to use the official libFLAC, invoked via the Java native interface. See this blog post, under the headline “FLAC decoding with Java native interface” for an explanation of how it's done, with links to working code.
I have searched and found a few image scaling libraries for Java. But not sure which one to go with. I need to generate thumbnails from the image uploaded by server.
It would be great if you can tell which one's good and bad.
The list I have is:
JMagick
im4java
Thumbnailator
java-image-scaling
JAI
For my simple needs, Thumbnailator was perfect. Small lib; fluent, clean, well-documented API.
In my case, it was just "net.coobird" % "thumbnailator" % "0.4.8" dependency and:
//..
Thumbnails.of(originalFile)
.size(300, 300)
.toFile(thumbnailFile)
//..
and done. Basically it’s a friendly wrapper on top of the Java 2D APIs. Useful for specific (thumbnailin') needs; no learning curve.
Unless you really need to do some heavy-lifting with images, I'd be wary of depending on an external binary (ImageMagick and wrappers like JMagick), which would add complexity and moving parts into the setup. Especially if your stack is something like mine: Scala/Java app running on Heroku. There’s stuff like heroku-buildpack-imagemagick-cedar-14, yes, but a simple dependency bundled with the app is infinitely cleaner.
Java API to generate thumbnails is not good enough if you need high quality thumbnails.
To generate high quality thumbnails use a framework like the ones you have listed. I have tried ImgScalr (https://github.com/thebuzzmedia/imgscalr) and Thumbnailator.
With my microbenchmark tests (cannot really be used for general purpose conclusions) Thumbnailator is faster - though not by a lot, and easier - especially when generating thumbnails with transparency.
I also trying out JMagick but running into issues just compiling the code and setting it up. Also a little worried about running into issues later with a framework whose basic code is written in a language I don't understand at all - C.
You might also find useful the discussion here: How can I resize an image using Java?
In my private projects, I don't use any specific library, the functionality provided for Java gives decent results for me. If you just want to do image scaling, then a complete image processing library would be too heavyweighted.
I use the code snippets given in http://www.mkyong.com/java/how-to-resize-an-image-in-java/ which works quite well.
I'm planning to make a simple Photo Resizer since I usually find myself having to resize huge images being sent to me. I know that there are a lot of online services and tools out there that already do this but I was thinking that it would be a good time to improve my Java and build something useful at the same time.
The problem is that I don't know where to start. I've looked around and mostly saw similar projects made in C# and C++.
Any tips on how to start this?
I did this some years ago to generate thumbnails. IIRC, you can use the ImageIO classes to read the image in as one format, and then write it back out as a different format/resolution.
edit: Oh, and here's Sun's tutorial on working with images. http://java.sun.com/docs/books/tutorial/2d/images/index.html
do i need "Java Advanced Imaging API" to learn "image processing" in Java?
and is there any good link for learning "image processing" in java?
If you are looking for learning very basic stuff, I'd say you should not start with JAI, because this library will help you processing images easily, but not learning how to process images -- you won't get to know the really low level stuff, like how to manipulate pixel arrays directly.
I started by reversing the image, cropping the image, creating histograms, doing histogram equalization, various affine transformation (scaling, rotating) etc.
This lecture might be a good start..
http://kevin.floorsoup.com/scholarship/ip2d/p12-burger.pdf
Sorry if you were looking for more sophisticated stuff :)
I'd say that if you want to learn image processing then you don't need JAI. At university we played around with PGM files, learned how to do basic transforms, basic filtering etc.
PGM is very easy to work with since it's greyscale and you can encode the image using ASCII. This means you can knock up a bit of code to read and write them in no time and then you can start building your own implmentation of image processing algorithms.
Check it out here: http://en.wikipedia.org/wiki/Portable_Gray_Map
Obviously if you want to do some serious image processing then check out a real API, but if you're wanting to play about and learn then this is where I'd start.
It depends on what you mean by "to learn". If you want to understand the foundations of image processing, then, no, you don't need anything beyond a basic familiarity with the ImageIO class for reading and writing images, and the BufferedImage getRGB() and setRGB() methods.
If you want to learn how to use existing APIs for image processing, you can still get a lot done with the Java2D API, but the JAI gives you more file formats and more filters.
But in that case, I'd say try Python Imaging Library!
If your needs go beyond basic operations - I think the best toolkit out there to learn the entire gamut of image processing (from basic to advanced such as object recognition/computer vision) is Open CV. There are plenty of Open CV wrappers for Java.
Consider Processing, it is based on Java (some extensions, like a color data type). The tutorials provide good introductions to general image processing concepts.
"Processing is an open source programming language and environment for people who want to create images, animations, and interactions." http://www.processing.org
No. However, there is a good Java program called "ImageJ" (google it).
It will get you off to a flying start, as you can start writing your own plugins for it in Java, with minimal effort and complexity. Also, there are many plugins and classes contributed for it and freely available.
I have explored several leads (sample apps) in the JAI/ImageIO arena, and have so far come up lacking in performance.
It may just be that Java is not the platform for fast viewing/scaling/editing of tiff files.
I am looking to produce performance similar to Irfanview, but so far haven't found what I am looking for.
JAI\ImageIO seems possible - but there seems to be many variations in how one can load/scale/display the images (in so far as performance is concerned).
Anyone have any luck or recommendations for other rocks to turn over (other libraries, or even JNI c extension route) would love to hear them!
I would really recommend the JAI/ImageIO route.
Several years ago I had this same issue of displaying massive tiff files for cropping rotation etc, and after spending some good time with JAI I was able to work with the tiff images without any issues of performance. These were in excess of 90Mb
I'm not able to recall any usefull tips, but you are going in the right direction with JAI.
I would imagine the performance has increased over the years too :)