标签:style blog color io os ar 数据 div sp
#pragma mark - 将图片转为二进制 + (NSString *)image2binaryWithImage:(UIImage *)image imageName:(NSString *)imgName { //获取图片的二进制数据 NSData *imageData = UIImageJPEGRepresentation(image, 0.65); // if (UIImagePNGRepresentation(image) == nil) { // imageData = UIImageJPEGRepresentation(image, 0.65); // } else { // imageData = UIImagePNGRepresentation(image); // } //把二进制数据转为Base64编码的字符串 NSString *dataStr = [Base64Tools encodeBase64Data:imageData]; //获取沙盒目录、将图片写入到本地 if (![imgName isEqualToString:@""]) { NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imgName]; [imageData writeToFile:filePath atomically:YES]; } return dataStr; }
//第三方工具方法
+ (NSString*)encodeBase64Data:(NSData*)data { data = [GTMBase64 encodeData:data]; NSString *base64String = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding] ; return base64String; }
标签:style blog color io os ar 数据 div sp
原文地址:http://www.cnblogs.com/hw140430/p/3970369.html