Is there a Java library for rotating JPEG files in increments of 90 degrees, without incurring image degradation?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Regarding the issue of EXIF data not necessarily being handled correctly, since EXIF data is irrelevant in many situations, here's example code demonstrating only the LLJTran lossless JPEG rotation feature (with thanks to user113215):
If you make the input and output
File
objects refer to the same file, you can run this over and over again, and observe that the image does not degrade, no matter how many iterations it is put through.You don't need an external library for this kind of thing, it's all built into SE. The easiest being the rotate() function of the Graphics2D object.
For example:
no loss!
Or, if you want to be extra careful, just use BufferedImage.getRGB(x,y), and translate it pixel by pixel on to the new image.
I found this: http://mediachest.sourceforge.net/mediautil/
API: http://mediachest.sourceforge.net/mediautil/javadocs/mediautil/image/jpeg/LLJTran.html
Building on Henry's answer, here's an example of how to use MediaUtil to perform lossless JPEG rotation based on the EXIF data: