jinglecode
 1 typedef NS_ENUM(NSInteger, NSPUIImageType)
 2 {    NSPUIImageType_JPEG,   
 3     NSPUIImageType_PNG,    
 4     NSPUIImageType_Unknown
 5 };
 6 static inline NSPUIImageType NSPUIImageTypeFromData(NSData *imageData) 
 7 {
 8     if (imageData.length > 4) {
 9         const unsigned char * bytes = [imageData bytes];
10 
11         if (bytes[0] == 0xff &&
12             bytes[1] == 0xd8 &&
13             bytes[2] == 0xff)
14         {
15             return NSPUIImageType_JPEG;
16         }
17 
18         if (bytes[0] == 0x89 &&
19             bytes[1] == 0x50 &&
20             bytes[2] == 0x4e &&
21             bytes[3] == 0x47)
22         {
23             return NSPUIImageType_PNG;
24         }
25     }
26 
27     return NSPUIImageType_Unknown;
28 }

 

分类:

技术点:

相关文章:

  • 2021-11-30
  • 2021-11-28
  • 2021-10-19
  • 2021-11-18
  • 2021-07-26
  • 2021-07-01
  • 2021-12-22
  • 2021-12-04
猜你喜欢
  • 2021-11-17
  • 2021-06-06
  • 2021-11-28
  • 2021-09-03
  • 2021-11-19
  • 2021-11-18
  • 2021-11-24
相关资源
相似解决方案