【发布时间】:2018-02-28 11:41:17
【问题描述】:
我有以下代码从库中选择一个图像,然后 base64encode 以供将来上传...图像已选择并根据我的需要出现在应用程序中...但是在输出中我收到此错误
发现扩展时遇到[discovery] 错误:Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
如果我在输出中使用打印的 base64 代码并使用 webtool (https://www.base64decode.org/) 尝试解码所述信息,以确认它已经工作,然后我稍后开始在 iOS 中进行解码 - 它似乎是畸形?我假设我仍然没有正确编码图像?
@IBAction func selectImage(_ sender: AnyObject) {
selectImage.allowsEditing = true //2
selectImage.sourceType = .photoLibrary //3
present(selectImage, animated: true, completion: nil)//4
}
func imagePickerController(_ selectImage: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage //2
profilePic.contentMode = .scaleAspectFit //3
profilePic.image = chosenImage //4
let quality = 1.0
base64String = (UIImageJPEGRepresentation(chosenImage, CGFloat(quality))?.base64EncodedString())!
print (base64String)
self.dismiss(animated: true, completion: nil) //5
}
【问题讨论】:
标签: ios swift uiimage base64 encode