//图片--》data--》base64格式的data--》utf8格式的字符串
+ (NSString *)convertToBase64ImageStr:(UIImage *)image{
NSData *imageData = UIImageJPEGRepresentation(image,0.1);
NSData * base64Data = [imageData base64EncodedDataWithOptions:0];
NSString *base64Str = [[NSString alloc]initWithData:base64Data encoding:NSUTF8StringEncoding];
return base64Str;
}
// utf8格式的字符串--》base64格式的data--》data--》图片
- (UIImage *)stringToImage:(NSString *)str {
NSData * base64Data =[str dataUsingEncoding:NSUTF8StringEncoding];
NSData * imageData = [[NSData alloc] initWithBase64EncodedData:base64Data options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage *photo = [UIImage imageWithData:imageData ];
return photo;
}
网友评论