我只是想在 swift 中使用 new,
我有一个按钮,点击它打开 iPad 的前置摄像头并点击用户的照片,当点击使用照片时,
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
正在调用 imagePickerController
这是一行代码..
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
picker .dismissViewControllerAnimated(true, completion: nil)
photoImgView.image=info[UIImagePickerControllerOriginalImage] as? UIImage
if imageData == nil {
imageData = UIImageJPEGRepresentation((info[UIImagePickerControllerOriginalImage] as? UIImage)!, 1)
}
}
但是当我提交时它显示找到了 nil value
,
调试后在 func didFinishPickingMediaWithInfo
中得到这一点
它说,
(lldb) po imageData
expression produced error: Execution was interrupted, reason: step over.
The process has been returned to the state before expression evaluation.
我没有明白我做错了什么。 因为我不擅长 swift,任何人都可以指导我吗? 我被困在这一点上。
提前致谢。
最佳答案
我得到了解决方案, 感谢我的同事,
我正在从 imagePickerController 捕获图像并保存在 NSData
中。
但图像捕获它大约 6-7 MB(iPad 相机默认捕获此大小的图像)
将其保存到 NSData
中,然后将其转换为 base64 格式时,大小超出范围,然后编译器会抛出问题。
只需更改 UIImageJPEGRepresentation
的行代码即可解决问题
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
photoImgView.image=info[UIImagePickerControllerOriginalImage] as? UIImage
imageData = UIImageJPEGRepresentation((info[UIImagePickerControllerOriginalImage] as? UIImage)!, 0.5)
print(imageData)
picker .dismissViewControllerAnimated(true, completion: nil)
}
关于xcode - expression produced error : Execution was interrupted, reason : step over. 过程已经返回到表达式求值前的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37789164/