I found that commons imaging library fits my needs best of all, but there is a lack samples of this library usage. Does anyone have an example how to rotate jpeg image lossless (i.e. by changing file metadata only)? Thanks!
Asked
Active
Viewed 1,105 times
2 Answers
0
There is a class RotatedIcon (see links) that can be used like this
if (imageOrientation.equals("3")) {
rotatedIcon = new RotatedIcon(imageIcon, RotatedIcon.Rotate.UPSIDE_DOWN);
} else if (imageOrientation.equals("6")) {
rotatedIcon = new RotatedIcon(imageIcon, RotatedIcon.Rotate.DOWN);
} else if (imageOrientation.equals("8")) {
rotatedIcon = new RotatedIcon(imageIcon, RotatedIcon.Rotate.UP);
}
imageOrientation is a property of image meta data (e.g. EXIF)

MLindwurm
- 3
- 2
-
Hello, Thank you for an answer but what I wanted is to rotate image lossless, with preserving EXIF data in the image. There are at least two libraries, which may do the trick: LLJTran and Commons Imaging (ex. Sanselan). LLJTran does not support some modern EXIF fields, thus I wanted to rotate JPEGs with Apache Commons Imaging but cannot find a code sample for it. – Alexey Ce Feb 16 '15 at 08:14
0
See the answer to this question on how to add/remove meta data using the Commons Imaging library.
The tag you would want to set is org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants#TIFF_TAG_ORIENTATION
.

nils
- 390
- 2
- 12