面膜效果是旋转照片

问题描述:

我的代码拍了一张照片。然后将其应用于其上的遮罩效果进行保存。唯一的问题是它从我拍摄人像照片的方向上被保存在-90。我想要做的只是拍摄一张肖像照片,然后将照片保存在旋转的照片上。面膜效果是旋转照片

[保存产品图当面具被应用] [2]

[蒙] [3]

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 

    let red = info[UIImagePickerControllerOriginalImage] as! UIImage 
      self.dismiss(animated: true) 
//Sugguested Code 
    red.imageOrientation = UIDevice.current.orientation.imageOrientation 
// 


    self.currentImageView?.image = red 

    let image = photo.image 
     let maskingImage = UIImage(named: "mask") 
    photo.image = maskImage(image: image!, mask: maskingImage!) 
    photo.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleBottomMargin, .flexibleRightMargin, .flexibleLeftMargin, .flexibleTopMargin] 
    photo.contentMode = .scaleAspectFit 
    photo.clipsToBounds = true 

    } 
+0

你需要采取肖像一个图像,然后上然后将其保存敷个面膜,但你的结果图像保存景观? –

+0

是的,这正是发生的事情。 –

+0

保存图像后蒙版的方向是否为真? –

当您创建的UIImage的,你需要确保你给他们正确的方向。这将让从手机的方向,并将其应用到图像

extension UIDeviceOrientation { 
    public var imageOrientation: UIImageOrientation? { 
     switch self { 
     case .portrait: return .right 
     case .portraitUpsideDown: return .left 
     case .landscapeLeft: return .up 
     case .landscapeRight: return .down 
     default: return nil 
     } 
    } 
} 
image.imageOrientation = UIDevice.current.orientation.imageOrientation 
+0

我认为这会奏效。我在哪里可以调用“image.imageOrientation = UIDevice.current.orientation.imageOrientation”。鉴于没有加载? –

+0

无论你在哪里创建图像。 – Spads

+0

图像保存在func saveImage中。选择要保存的照片的位置。是否应该去哪里? –