Created
August 1, 2015 04:54
-
-
Save harry1064/7afe7aad016843ef0ed0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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