//通过图片Data数据第一个字节 来获取图片扩展名
- (NSString*)contentTypeForImageData:(NSData*)data
{
uint8_t c;
[datagetBytes:&clength:1];
switch(c)
{
case0xFF:
return@"jpeg";
case0x89:
return@"png";
case0x47:
return@"gif";
case0x49:
case0x4D:
return@"tiff";
case0x52:
if([datalength] <12) {
returnnil;
}
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if([testStringhasPrefix:@"RIFF"]
&& [testStringhasSuffix:@"WEBP"])
{
return@"webp";
}
returnnil;
}
return nil;
}