Bildausrichtung erkennen und drehen

Hallo in die Runde.

Hat jemand eine fertige Methode, die die Bildausrichtung ausliest/erkennt und das Bild dann passend dreht?

Wenn es nichts fertiges gibt, wie erkenne ich die Bildausrichtung (z. B. bei einer jpg-Datei)?

Gru, Stefan Mettenbrink.

You only have to do this on Windows.
Mac handles it for you

Graphicsmagik MBS plugins can help

[code]
// F is a folderitem pointing to an image on disc

dim orient as string
dim bhavetorotate as boolean
dim a_pic as picture

    if TargetWin32 then

      try
        
        dim gorig as new GMImageMBS(f)
        orient = gorig.attributeValue("EXIF:Orientation")
        
        if  orient = "6"  then
        // "Needs rotation by 90"
          bhavetorotate = true
          gorig.rotate 90
          a_pic = gorig.CopyPicture
          
        end if
        
        if  orient = "8"  then
         // "Needs rotation by -90"
          bhavetorotate = true
          gorig.rotate -90
          a_pic = gorig.CopyPicture
          
        end if
       
      catch
        if bDebug then WriteLog "Problem getting EXIF data.. fallback to just open the file."

      end try
      if not bhavetorotate then
        a_pic = picture.open(f)
      end if

//a_pic now holds correctly oriented picture
#else
…mac[/code]

Danke für den Code, funktioniert prima!

Fehlt da nicht noch die 18° Drehung?

Irgendwie so:

[code]if orient = “3” then
// “Needs rotation by 180”
bhavetorotate = true
gorig.rotate 180
a_pic = gorig.CopyPicture

        end if

[/code]

Siehe auch hier:

Ich hatte neulich dasselbe Problem mit einem einzelnen Bild. Ich habe es in die Vorschau geladen und von dort aus in eine Kopie gesichert. Danach war die Ausrichtung in den EXIF-Attributen von 3 auf 1 gesetzt und das Bild wurde in Windows richtig dargestellt. Im macOS war es immer richtig angezeigt.

Das ist nicht das, was ich möchte.
Sicher kann ich für mich so vorgehen. Aber wenn ich ein Programm schreibe, dann möchte ich es dem Anwender so einfach wie möglich machen. Dazu gehört dann, dass das Bild in der korrekten Lage angezeigt wird (wie es andere Programme ja auch machen).