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
Here is the output of String which i am getting
here is my code:
// 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)
}
In Swift 3.0 func decodeBase64(toImage strEncodeData: String) -> UIImage { let dataDecoded = NSData(base64Encoded: strEncodeData, options: NSData. Base64DecodingOptions. ignoreUnknownCharacters)! let image = UIImage(data: dataDecoded as Data) return image! }
Actually it will not take time to convert but for printing, it will take more time so don't print it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With