public Image ProcessImage(ImageFactory factory)
{
Image image = factory.Image;
try
{
const int Orientation = (int)ExifPropertyTag.Orientation;
if (!factory.PreserveExifData && factory.ExifPropertyItems.ContainsKey(Orientation))
{
int rotationValue = factory.ExifPropertyItems[Orientation].Value[0];
switch (rotationValue)
{
case 8:
// Rotated 90 right
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
case 7: // Rotated 90 right, flip horizontally
image.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 6: // Rotated 90 left
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 5: // Rotated 90 left, flip horizontally
image.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 3: // Rotate 180 left
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 2: // Flip horizontally
image.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
}
}
return image;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
}