Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harry1064/7afe7aad016843ef0ed0 to your computer and use it in GitHub Desktop.
Save harry1064/7afe7aad016843ef0ed0 to your computer and use it in GitHub Desktop.
Objective-C
iOS7 > version
You can use NSData's base64EncodedStringWithOptions
Encoding :
- (NSString *)encodeToBase64String:(UIImage *)image {
return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
Decoding :
- (UIImage *)decodeBase64ToImage:(NSString *)strEncodeData {
NSData *data = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters];
return [UIImage imageWithData:data];
}
iOS 6.1 and < version
First Option : Use this (http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php) to encode and decode image
Add Base64(http://www.imthi.com/wp-content/uploads/2010/08/base64.zip) class in your project.
Encoding :
NSData* data = UIImageJPEGRepresentation(yourImage, 1.0f);
NSString *strEncoded = [Base64 encode:data];
Decoding :
NSData* data = [Base64 decode:strEncoded ];;
image.image = [UIImage imageWithData:data];
Another Option: Use QSUtilities for encoding and decoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment