快速将图像转换为BASE64字符串 [英] Converting Image to BASE64 String in swift
本文介绍了快速将图像转换为BASE64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试转换用户从其照片或从相机拍摄的新照片中选择的图像.我能够将图像转换为base64字符串,但问题是它花费了太多时间并打印了一个长的无限字符串
I am trying to convert the Image which is picked by user either from his Photos or Take New from Camera. I am able to convert the image into base64 string but the problem is that it takes too much time and prints a long infinite string
这是我得到的String的输出
Here is the output of String which i am getting
这是我的代码:
// Image picker from Gallery
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)
profileImage.image = image
}
// Image Picker from Camera
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)
profileImage.image = info[UIImagePickerControllerOriginalImage] as? UIImage
addPicBtn.setImage(nil, forState: .Normal)
let imageData:NSData = UIImagePNGRepresentation(profileImage.image!)!
let imageStr = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
print(imageStr)
}
推荐答案
实际上,转换不会花费时间,但要进行打印,会花费更多时间,所以请不要打印...
Actually it will not take time to convert but for printing, it will take more time so don't print it...
这篇关于快速将图像转换为BASE64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文