Created
October 27, 2016 18:27
-
-
Save dgyesbreghs/9b18494ea2002a6fba51954e86542b6a to your computer and use it in GitHub Desktop.
Encode UIImage to Base64 string
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
// | |
// NSString+Base64.h | |
// Pods | |
// | |
// Created by Dylan Gyesbreghs on 27/10/2016. | |
// | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSString (Base64) | |
- (UIImage *)base64Decoding; | |
@end |
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
// | |
// NSString+Base64.m | |
// Pods | |
// | |
// Created by Dylan Gyesbreghs on 27/10/2016. | |
// | |
// | |
#import "NSString+Base64.h" | |
@implementation NSString (Base64) | |
- (UIImage *)base64Decoding | |
{ | |
NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters]; | |
return [UIImage imageWithData:base64Data]; | |
} | |
@end |
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
// | |
// UIImage+Base64.h | |
// Pods | |
// | |
// Created by Dylan Gyesbreghs on 27/10/2016. | |
// | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIImage (Base64) | |
- (NSString *)base64Encoding; | |
@end |
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
// | |
// UIImage+Base64.m | |
// Pods | |
// | |
// Created by Dylan Gyesbreghs on 27/10/2016. | |
// | |
// | |
#import "UIImage+Base64.h" | |
@implementation UIImage (Base64) | |
- (NSString *)base64Encoding | |
{ | |
return [UIImagePNGRepresentation(self) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment