判断图片格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
+(NSString *)typeForImageData:(NSData *)data
{
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"jpeg";

case 0x89:
return @"png";

case 0x47:
return @"gif";

case 0x49:

case 0x4D:
return @"tiff";
}
return nil;
}