我刚刚开始新的,
点击iPad的前置摄像头,点击用户照片,点击"使用照片",
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
Run Code Online (Sandbox Code Playgroud)
正在被召唤 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)
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我提交它时显示发现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.
Run Code Online (Sandbox Code Playgroud)
我没有得到我做错的事.因为我不是很好,所以任何人都可以指导我.我被困在这一点上.
提前致谢.
感谢我的同事,我得到了解决方案
我正在从 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)
}
Run Code Online (Sandbox Code Playgroud)