iosswiftuiimageviewuiimageuipickerviewcontroller

UIimage Detect Landscape Image with Swift


I want to read a photo from Library

in this function

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

now I want to know is that landscape photo or not I try to tie this code

if(pickedImage?.size.width > pickedImage?.size.height)

But I received this error Binary operator '>' cannot be applied to two 'CGFloat?' operands how can I resolve this Problem


Solution

  • Try this

     if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
    
       { 
          if pickedImage.size.width > pickedImage.size.height 
          {
             /// landscape mode
          }
    
       }
    
    }