我需要在Objective-C中确定需要下载和显示的图像是否为渐进式JPEG。我做了一些搜索,但没有找到任何明显的方法。你能帮忙吗?
答案 0 :(得分:2)
答案 1 :(得分:2)
在做了一些更多的研究之后,我发现了一些关于在iOS上可以做到的方式的更多信息。
按照我在Technical Q&A QA1654 - Accessing image properties with ImageIO中读到的内容,我这样做了:
//Example of progressive JPEG
NSString *imageUrlStr = @"http://cetus.sakura.ne.jp/softlab/software/spibench/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");