Does anyone know how to convert a UIImage
to a Base64 string, and then reverse it?
I have the below code; the original image before encoding is good, but I only get a blank image after I encode and decode it.
NSData *imageData = UIImagePNGRepresentation(viewImage);
NSString *b64EncStr = [self encode: imageData];
NSString *base64String = [self encodeBase64:imageData];
SWIFT 3.0, XCODE 8.0
Replace String with your URL. and testImage is an outlet of ImageView
Hope It Helps Thanks.
In swift 2.0 use this extension (credit to Jonas Franz)
Swift-Extension:
I tried all the solutions, none worked for me (using Swift 4), this is the solution that worked for me, if anyone in future faces the same problem.
Swift 4.2, Xcode 10.1
let imageData = UIImage(named:"imagename").pngData()?.base64EncodedString(options: .lineLength64Characters)
print(imageData)