发送过滤图像的电子邮件

时间:2019-03-18 17:49:51

标签: ios swift

我有一张将被高斯模糊滤除的图像。

 @IBAction func gausBtn(_ sender: Any) {
    print("gaus")
    let originalImage = CIImage(image: image!)
    let filter = CIFilter(name: "CIGaussianBlur")
    filter?.setDefaults()
    filter?.setValue(originalImage, forKey: kCIInputImageKey)
    if let outputImage = filter?.outputImage {
        let newImage = UIImage(ciImage: outputImage)
        imageView.image = newImage
        print("set image")
        emailBtn.isEnabled = true
    }else{
        print("error")
    }
}

然后,我想在按下按钮后通过电子邮件发送编辑后的图像。

@IBAction func emailAction(_ sender: Any) {
    if MFMailComposeViewController.canSendMail() {
        let mail = MFMailComposeViewController()
        mail.mailComposeDelegate = self;
        mail.setCcRecipients([])
        mail.setSubject("Edited Photo")
        mail.setMessageBody("Hi\n, the edited photo is attached!", isHTML: false)
        mail.addAttachmentData((imageView.image?.pngData())!, mimeType: "image/png", fileName: "edit.png")
        self.present(mail, animated: true, completion: nil)
    }
}

该代码在尚未编辑图像时有效,但是在编辑时pngData返回nil导致崩溃。我如何获取“转换后的” ciImage的pngData?

0 个答案:

没有答案