Alexey Ce
Alexey Ce

Reputation: 13

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!

Upvotes: -1

Views: 1350

Answers (2)

nils
nils

Reputation: 410

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.

Upvotes: 0

MLindwurm
MLindwurm

Reputation: 3

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)

https://tips4java.wordpress.com/2009/04/06/rotated-icon/

https://github.com/griffon/griffon-javatips-plugin/blob/master/src/main/com/wordpress/tipsforjava/swing/RotatedIcon.java

Upvotes: 0

Related Questions