I am doing a 90° rotation with minimal loss, using the following code:
System.Drawing.Image originalImage = System.Drawing.Image.FromFile("input.jpg");
ImageFormat sourceFormat = originalImage.RawFormat;
EncoderParameters encoderParams = null;
try
{
if (sourceFormat.Guid == ImageFormat.Jpeg.Guid)
{
encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = new EncoderParameter(Encoder.Transformation,
(long)EncoderValue.TransformRotate90);
}
originalImage.Save("output.jpg", GetEncoder(sourceFormat), encoderParams);
}
finally
{
if (encoderParams != null)
encoderParams.Dispose();
}
However the Save
function seems to create EXIF metadata from the original (pure, no EXIF) JPEG COM marker (0xFE). I do not want EXIF markers in the output JPEG. I also want to preserve the original COM marked. What C# API in my application can I use instead to save my rotated buffer ?
Using jpegdump (dicom3tools package):
$ jpegdump < input.jpg
[...]
Offset 0x0014 Marker 0xfffe COM Comment length variable 0x10
While:
$ jpegdump < output.jpg
[...]
Offset 0x0014 Marker 0xffe1 APP1 Reserved for Application Use length variable 0x5a