【发布时间】:2016-07-19 06:39:22
【问题描述】:
我正在尝试通过点击 captureDoc 按钮来捕获图像。但是当我点击捕获按钮时,我收到一个错误“无法将 UIImage 类型的值转换为 NSString”。下面是我的操作按钮代码。
@IBAction func captureDoc(sender: AnyObject) {
weak var weakSelf = self
self.scanDoc.captureImageWithCompletionHander({(imageFilePath) -> Void in
let captureImageView: UIImageView = UIImageView(image: UIImage(contentsOfFile: imageFilePath as! String))
captureImageView.backgroundColor = UIColor(white: 0.0, alpha: 0.7)
captureImageView.frame = CGRectOffset(weakSelf!.view.bounds, 0, -weakSelf!.view.bounds.size.height)
captureImageView.alpha = 1.0
captureImageView.contentMode = .ScaleAspectFit
captureImageView.userInteractionEnabled = true
weakSelf?.view.addSubview(captureImageView)
let dismissTap: UITapGestureRecognizer = UITapGestureRecognizer(target: weakSelf, action: #selector(self.dismissPreview))
captureImageView.addGestureRecognizer(dismissTap)
UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.7, options: .AllowUserInteraction, animations: {
captureImageView.frame = weakSelf!.view.bounds
}, completion: nil)
})
}
我收到此错误是因为我将 imageFilePath 作为 AnyObject,但在下面的语句中我们必须传递字符串。所以我真的很困惑该怎么办。如果有人能弄清楚问题是什么。 谢谢!
UIImage(contentsOfFile: imageFilePath as! String)
【问题讨论】:
-
好像你已经得到了一个图像,而不是图像的路径
-
是的,现在我该怎么办?? @Wain