【发布时间】:2016-01-14 05:38:40
【问题描述】:
我需要在 Objective-C 中确定需要下载和显示的图像是否是渐进式 JPEG。我做了一些搜索,但没有找到任何明显的方法。你能帮忙吗?
【问题讨论】:
标签: ios objective-c iphone cocoa-touch uiimage
我需要在 Objective-C 中确定需要下载和显示的图像是否是渐进式 JPEG。我做了一些搜索,但没有找到任何明显的方法。你能帮忙吗?
【问题讨论】:
标签: ios objective-c iphone cocoa-touch uiimage
在做了更多研究后,我发现了更多关于如何在 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");
【讨论】:
【讨论】: