Image orientation ios

I’m having problems getting my images on my ios app to have the correct orientation. EXIF for the orientation = 6 but I can’t get it to autorotate. I’m using MBS, the messagebox says it’s rotated but its not…If orientation = 1 I’m not having any issues because these don’t need rotating.

Dim ciImage As New CIImageMBS(file)
Dim properties As Dictionary = ciImage.Properties

If properties.HasKey("Orientation") Then
  Dim orientation As Integer = properties.Value("Orientation")
  MEssageBox("EXIF Orientation: " + orientation.ToString)
  
  If orientation = 6 Then // Rotate 90° CW
    var transform as new NSAffineTransformMBS
    transform.rotateByDegrees(270)
    
    // Use filter
    var f as new CIFilterAffineTransformMBS
    f.inputImage = ciImage
    f.inputTransform = transform
    
    Dim rotated As CIImageMBS = f.OutputImage
    
    // Create output
    Dim context As New CIContextMBS
    Dim extent As CGRectMBS = rotated.Extent
    Dim cgPic As CGImageMBS = context.createCGImage(rotated, extent)
    
    If cgPic <> Nil Then
      p = cgPic.Picture
      MEssageBox("Returning rotated picture: " + p.Width.ToString + " x " + p.Height.ToString)
    Else
      MEssageBox("CGImageMBS was NIL!")
    End If

not sure why that wasn’t working but this is

Var p As Picture = origP

#If MBS.HasMacCIPlugin Then
  Dim ciImage As New CIImageMBS(file)
  Dim props As Dictionary = ciImage.Properties
  
  Dim orientation As Integer = 1
  If props.HasKey("Orientation") Then
    orientation = props.Value("Orientation").IntegerValue
  End If
  
  System.DebugLog("EXIF Orientation: " + orientation.ToString)
  
  Dim finalPic As Picture
  
  If orientation > 1 Then
    ciImage = ciImage.imageByApplyingOrientation(orientation)
  End If
  
  Dim context As New CIContextMBS
  Dim extent As CGRectMBS = ciImage.Extent
  System.DebugLog("CIImage Extent: " + extent.Width.ToString + " x " + extent.Height.ToString)
  
  Dim cgPic As CGImageMBS = context.createCGImage(ciImage, extent)
  
  If cgPic <> Nil Then
    p = cgPic.Picture
    System.DebugLog("After CI transform: " + p.Width.ToString + " x " + p.Height.ToString)
  Else
    System.DebugLog("CGImageMBS NIL — fallback to original")
    p = origP
  End If
  
  //
  // 🔍 Robust fallback logic:
  //
  If orientation = 6 Then
    
    // If after transform the image is still landscape but should be portrait, rotate.
    If p.Width > p.Height Then
      System.DebugLog("Fallback: width > height after EXIF 6 — Rotate270 to force portrait")
      p = p.Rotate90MBS
    End If
    
  End If
  
#EndIf

Return p
1 Like