'Sample of lossless image rotate via commons imaging
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!
Solution 1:[1]
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)
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MLindwurm |
| Solution 2 | nils |
