private void DirectoryMonitor_Created(object sender, System.IO.FileSystemEventArgs e) { //BitmapOrientationConverter d = new BitmapOrientationConverter(); //d.Convert(e.FullPath); // WAIT A COUPLE OF SECOND TO MAKE SURE IMAGE HAS FINISHED WRITING. System.Threading.Thread.Sleep(1000); ExifMetaInfo emi = null; // DETERMINE IF IMAGE NEEDS TO BE ROTATED IN ITS OWN PROCESS try { emi = new ExifMetaInfo(e.FullPath); try { // TODO: Log Error this.ProcessImage(e.FullPath, emi); } catch (Exception ex) { MessageBox.Show("An error was encountered when processing the image.", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { // TODO: Log Error MessageBox.Show("An error was encountered when reading the Exif Metadata.", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
private void ProcessImage(string FullPath, ExifMetaInfo EMI) { System.Drawing.Bitmap image = new System.Drawing.Bitmap(FullPath); // EXIT IF IMAGE IS IN CORRECT ORIENTATION if (EMI.Orientation.Key == 1) { return; } switch (EMI.Orientation.Key) { case 1: // IS IN CORRECT ORIENTATION break; case 2: image.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); break; case 3: break; case 4: break; case 5: break; case 6: image.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); break; case 7: break; case 8: image.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); break; default: break; } try { image.Save(FullPath, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception ex) { //throw; } image.Dispose(); }