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)
}
Make sure your image extension first.
// .png
// .JPEG
// BASE 64
Actually it is not taking time to convert(very less time) for printing it will take more time so don't print it....
You can apply this code