CodeKat.NET
CodeKat.NET

Reputation: 63

90 degree image rotation and reset EXIF rotation

I have code to batch resize digital photos.

Some photos are taken in portrait orientation.

For the photos in portrait orientation, I have to rotate them.

I am using the following C# code to rotate the photo:

bmpOrig.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
bmpOrig.Save(filename, ImageFormat.Jpeg);

It works fine (displays the way I want in a web browser).

However, if I view the new image in Photoshop (and HP photo viewer) it displays rotated.

I have done a lot of research and I believe there is EXIF data that flags the image is rotated.

My question is: How do I reset this EXIF data to indicate that the image does not need to be rotated?

I'm developing in VS 2010.

Thanks

Upvotes: 3

Views: 4132

Answers (3)

Darkseal
Darkseal

Reputation: 9564

The Exif Orientation Tag id is 0x0112.

You can use img.GetPropertyItem(0x0112) to retrieve it and then img.RemovePropertyItem(0x0112) to remove it (if you physically rotate the image to compensate that value).

See this answer for a small helper class that does just that (full source code included).

Upvotes: 1

M K. Price
M K. Price

Reputation: 228

As I understand, the EXIF info is stored in the Properties of the Image class, so take a look through them and remove the offending one.

Upvotes: 1

negEntropy
negEntropy

Reputation: 329

See if the Save command is actually writing the changes?

maybe make sure by enclosing the Write command in a try/catch block?

Upvotes: 2

Related Questions