如何确定图像是否是Objective-C中的逐行JPEG(隔行) [英] How to determine if an image is a progressive JPEG (interlaced) in Objective-C

查看:48
本文介绍了如何确定图像是否是Objective-C中的逐行JPEG(隔行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

经过更多研究,我发现了一些有关在iOS中完成操作的方法的信息。 / p>

技术问答QA1654-使用ImageIO访问图像属性我是这样的:

  //渐进式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);

imagePropertiesDictionary字典对于渐进式JPEG如下所示:

  imagePropertiesDictionary的打印描述字典:
{
ColorModel = RGB;
深度= 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(@这是一个渐进式JPEG);


I need to determine in Objective-C if an image, that needs to be downloaded and shown, is a progressive JPEG. I did some search but didn't find any obvious way. Can you help?

解决方案

After doing some more research I found some more info on the way it could be done in iOS.

Following what I read in Technical Q&A QA1654 - Accessing image properties with ImageIO I did it like this:

//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);

The imagePropertiesDictionary dictionary looks like this for a progressive JPEG:

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 means it's a progressive/interlaced JPEG. You can check the value like this:

CFDictionaryRef JFIFDictionary = (CFDictionaryRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyJFIFDictionary);

CFBooleanRef isProgressive = (CFBooleanRef)CFDictionaryGetValue(JFIFDictionary, kCGImagePropertyJFIFIsProgressive);

if(isProgressive == kCFBooleanTrue)
    NSLog(@"It's a progressive JPEG");

这篇关于如何确定图像是否是Objective-C中的逐行JPEG(隔行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆