iOS 通过二进制判断图片类型

+ (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;
}

 

posted @ 2016-08-06 14:32  SoulDu  阅读(1398)  评论(0编辑  收藏  举报