【问题标题】:How to determine if an image is a progressive JPEG (interlaced) in Objective-C如何在 Objective-C 中确定图像是否为渐进式 JPEG(隔行扫描)
【发布时间】:2016-01-14 05:38:40
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c iphone cocoa-touch uiimage


    【解决方案1】:

    在做了更多研究后,我发现了更多关于如何在 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");
    

    【讨论】:

      【解决方案2】:

      JPEG Format 包含several markers。

      渐进标记是

      \xFF\xC2
      \xFF\xDA
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-24
        • 2017-01-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多