0

When I resize my image and save it using the "System.Drawing.Imaging" save function, it adds the rotation embedded from the EXIF data and rotates my good original picture 180 degrees. I tried saving it in a different format to remove the EXIF data but it still includes the EXIF rotation for the new picture. Any ideas on how I can save the picture in the orientation I can see in the thumbnails .

Private Sub ClearEXIF() 
    Dim Pname As String = Nothing

    For Each Fil In Directory.GetFiles(DlDir)
        OK2Go = False
        If Fil.Contains("jpg") Then OK2Go = True
        If Fil.Contains("jpeg") Then OK2Go = True

        If OK2Go Then
            Dim bmp As Bitmap = Image.FromFile(Fil)

            Pname = GetLastName(Fil) 'this function gets the name of the jpg without the path info
            temp1 = Split(Pname, ".")

            bmp.Save("C:\Temp\Flat\" & temp1(0) & "+" & temp1(1) & ".png", ImageFormat.png)
            bmp.Dispose()
        End If

    Next
    MsgBox("Done")
End Sub
Craig
  • 2,248
  • 1
  • 19
  • 23
kaaewhy
  • 1
  • 2
  • `Dim bmp As Bitmap = new Bitmap(Fil, true)`. BTW, maybe `For Each imageFile as string In Directory.GetFiles(DlDir, "*.jp*g")` (remove the `If Fil.Contains()` conditions, which are bound to fail anyway) – Jimi Oct 14 '20 at 18:06
  • same condition. This time I displayed the bmp directly in a picturebox and it comes in upside down. original file is right side up. Thanks for the idea! – kaaewhy Oct 14 '20 at 19:27
  • Using the `new Bitmap()` method, the Image is stripped of the stored `PropertyItems` (leaving just the Luminance and Chrominance tables). So, what you see is what it is. Note that a PictureBox Control doesn't consider the EXIF Orientation anyway. If you took a photo with a device that allows the rotation of the screen (e.g., a cell phone), that device does consider the Orientation when it presents the Images. If you want to rotate the *physical* image, you have to redraw it (mirror/flipped). See [Image.RotateFlip](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.rotateflip). – Jimi Oct 14 '20 at 19:51
  • so do you think the picture was taken upside down and windows takes the EXIF orientation into consideration and views it right side up? – kaaewhy Oct 15 '20 at 02:37
  • What I'm saying is that a PictureBox Control doesn't rotate/flip an image based on the EXIF Orientation value specified in the PropertyItem at index `0x112` (`274`). Some viewers do, like those of rotating devices, as cell phones, tablets etc. If you want to rotate and flip the Image as you see it in one of these viewers, you have to rotate/flip it yourself, reading the PropertyItem's value and applying the corresponding `RotateFlip` setting. See [Images are rotated in PictureBox](https://stackoverflow.com/q/39068941/7444103) – Jimi Oct 15 '20 at 08:54
  • Note that EXIF metadata only applies to JPEG and TIFF Images: saving as PNG, the metadata information is lost and the Image is saved as-is (thus possibly rotated and flipped). – Jimi Oct 15 '20 at 09:03
  • Hi Jimi. I got it working thanks to your help. What I ended up doing was reading in a bitmap to get the EXIF rotation value, then reading in another "NEW" bmp that had no EXIF data and applying the rotations to the NEW one. Thanks a bunch!! PD I'd share the program but only have 289 characters left :( – kaaewhy Oct 15 '20 at 21:14
  • That's ok. Possibly, post the code and a description of the process that solves the problem as an answer (you can answer your own question, then accept it when it's possible). [Edit](https://stackoverflow.com/review/suggested-edits/27396142) your question if you have updates (to the question only, don't post an answer there). – Jimi Oct 15 '20 at 21:29

0 Answers0