我尝试了以下方法,但图像无法正确显示并且丢失
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
img_View.image = info[UIImagePickerControllerOriginalImage] as? UIImage
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let imageData:NSData = UIImagePNGRepresentation(image)!
strImage = imageData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
print(strImage)
dismissViewControllerAnimated(true, completion: nil)
}
这里有损图像Corrupted image here 当我将图像解码到我的计算机中时,我得到了稍微模糊的完整图像,但是当我将我的 base64 字符串发送到服务(WEBAPI)(Windows PC)时,它们只得到图像的一半。有人可以帮我解决这个问题吗
这个问题有点老了,但作为谷歌搜索结果 HitTest 门的问题之一,我将为 swift4 添加解决方案。
You need to define the option of encoding
let image = UIImage(named: "yourimagename")
let imageData = UIImagePNGRepresentation(image)
let base64Str = imageData?.base64EncodedString(options: .lineLength64Characters)
关于ios - 如何在 swift 2.0 中将图像转换为 base64 而不会丢失图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672422/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |