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
First we need to have image's NSData
Swift 2.0 > Encoding
Swift 2.0 > Decoding
Swift 3.0 > Decoding
Encoding :
Decoding :
Swift 3.0
Objective-C
iOS7 > version
You can use
NSData's
base64EncodedStringWithOptions
Encoding :
Decoding :
iOS 6.1 and < version
First Option : Use this link to
encode
anddecode
imageAdd Base64 class in your
project
.Encoding :
Decoding :
Another Option: Use QSUtilities for
encoding
anddecoding