#pragma mark ————————— 图片压缩 —————————————
+ (UIImage *)imageYaSuo:(UIImage *) image {
NSData *data = nil;
if(!UIImagePNGRepresentation(image)) {
data =UIImageJPEGRepresentation(image,0.5);
}else{
data =UIImagePNGRepresentation(image);
}
CGFloat length = [data length] / 1024;
NSLog(@"压缩完大小 = %.2f",length);
UIImage * newImage= [UIImage imageWithData:data];
return newImage;
}
#pragma mark ————————— 图片格式 —————————————
+ (NSString *)typeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
}
return nil;
}