My program processes some images in batch mode. I now need to read the exif orientation tag of the image, rotate it to the desired orientation, do some processing and save the image without any EXIF orientation tag, but with the right rotation. (or with an EXIF tag with the appropriate orientation)
I read EXIF and Rotating using this library :
var bmp = new Bitmap(pathToImageFile); var exif = new EXIFextractor(ref bmp, "n");
It works. but when you save this image, there is still an exif rotation tag that makes the image incorrect. What i can do is
var bmp = new Bitmap(OS.FileName); var exif = new EXIFextractor(ref bmp, "n"); exif.setTag(0x112, "1"); bmp.save("strippedexifimage");
But this code when used in a loop slows down my program by about 50%. Is there an alternative way? Maybe a code to resist image rotation after applying rotation, will this work?
Update:
@Hans Passant. Your answer works, but the result it produces is the same as those created by the library. When I use bitmap.save (), both the library and your code work. But when I use the following code to save my image depending on the format chosen by the user. Imgformat can be imgformat = "image/png";,imgformat = "image/jpeg"; etc. Some images are still saved with the wrong exif orientation tag. i.e.: I see an incorrect image view in Windows Explorer. When I open an image using MS Paint, the image has the correct orientation. What am I doing wrong? Please, help.
private void saveJpeg(string path, Bitmap img, long quality) { EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); ImageCodecInfo Codec = this.getEncoderInfo(imgformat); if (Codec == null) return; EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = qualityParam; img.Save(path + ext, Codec, encoderParams); } private ImageCodecInfo getEncoderInfo(string mimeType) {