/**
* 将md5的照片转化成json字符串
*
* @param checksumArray 装有照片MD5的数组
*
* @return json字符串
*/
- (NSString *)markChecksum:(NSArray *)checksumArray
{
if (!checksumArray || checksumArray.count == 0) {
return @"";
}
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:checksumArray options:0 error:nil];
if (!jsonData) {
return @"";
}
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
return jsonString;
}
/**
* 将图片data写入磁盘用于以后压缩
*
* @param imageData 图片的data
*/
- (void)writeImageData2File:(NSData *)imageData
{
if (imageData == nil) {
return;
}
//文件保存路径
NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [directoryPath stringByAppendingPathComponent:@"Nearby/mark/photo"];
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
[[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *imageMD5 = [self MD5StringWithData:imageData];
NSString *photoPath = [NSString stringWithFormat:@"%@/%@", filePath, [NSString stringWithFormat:@"%@.jpg", imageMD5]];
if ([[NSFileManager defaultManager] fileExistsAtPath:photoPath]) {
//文件重复,无效.
[[NSFileManager defaultManager] removeItemAtPath:photoPath error:nil];
}
if( [imageData writeToFile:photoPath atomically:YES]) {
if (imageMD5 && [imageMD5 length]) {
[_photoMD5Array addObject:imageMD5];
} else {
[_photoMD5Array addObject:@""];
}
[_photoPathArray addObject:photoPath];
}
}
/**
* 获取图片data的md5值
*
* @param data 压缩后的图片data
*
* @return 图片的md5值
*/
- (NSString *)MD5StringWithData:(NSData *)data
{
const unsigned char *signBytes = [data bytes];
unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
CC_MD5(signBytes, (int)data.length, outputBuffer);
NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for (NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++) {
[outputString appendFormat:@"%02X",outputBuffer[count]];
}
return outputString ;
}
/**
* 将上传的图片压缩成一个压缩包
*
* @return 返回压缩包路径
*/
- (NSString *)zipPhotoFile:(NSArray *)photoPathArray
{
//文件保存路径
NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [directoryPath stringByAppendingPathComponent:@"Nearby/mark"];
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
[[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *zipFile = [filePath stringByAppendingPathComponent:@"newzipfile.zip"];
if ([[NSFileManager defaultManager] fileExistsAtPath:zipFile]) {
[[NSFileManager defaultManager] removeItemAtPath:zipFile error:NULL];
}
ZipArchive *za = [[ZipArchive alloc] init];
[za CreateZipFile2:zipFile];
for (NSString *path in photoPathArray) {
[za addFileToZip:path newname:[path lastPathComponent]];
}
if ([za CloseZipFile2]) {
return zipFile;
}
return nil;
}
将md5的照片转化成json字符串
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 相信大部分人都知道或者去百度检索都会得到将js中的字符串转化成json对象常见的3种方法 举例: var str ...
- 这样的。找了很多资料,发现都得用图文混排的方式去处理,其中很多的表情字符串是[大哭]这样的形式,然后对于:sad:...