base 64ピクチャと文字列符号化の詳細手順
2145 ワード
base 64ピクチャと文字列符号化の詳細手順
base 64ピクチャ符号化プロセス
NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:path];
NSString *base64String = [data base64EncodedStringWithOptions:0]
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [cachePath stringByAppendingPathComponent:@"222.txt"];
[base64String writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:NULL];
base 64ピクチャ復号プロセス
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [cachePath stringByAppendingPathComponent:@"222.txt"];
NSData *base64Data = [NSData dataWithContentsOfFile:filePath];
NSData *data = [[NSData alloc] initWithBase64EncodedData:base64Data options:0];
self.imageView.image = [UIImage imageWithData:data];
base 64文字列符号化
NSData *data = [String dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64String = [data base64EncodedStringWithOptions:0];
base 64文字列復号
NSData *data = [[NSData alloc]initWithBase64EncodedString:base64String options:0];
NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
文字列コーデックプレゼンテーションの終了
転載は出典を明記しなければなりません.ありがとうございます.http://www.jianshu.com/p/3ab36ad3a18a