iOS中ImageIO框架詳解與應用分析

iOS中ImageIO框架詳解與應用分析

1、引言

    ImageIO框架提供了讀取與寫入圖片數據的基本方法,使用它能夠直接獲取到圖片文件的內容數據,ImageIO框架中包含6個頭文件,其中完成主要功能的是前兩個頭文件中定義的方法:git

1.CGImageSource.h:負責讀取圖片數據。windows

2.CGImageDestination.h:負責寫入圖片數據。數組

3.CGImageMetadata.h:圖片文件元數據類。緩存

4.CGImageProperties:定義了框架中使用的字符串常量和宏。網絡

5.ImageIOBase.h:預處理邏輯,無需關心。app

2、CGImageSource詳解

    CGImageSource類的主要做用是用來讀取圖片數據,在平時開發中,關於圖片咱們使用的最多的多是UIImage類,UIImage是iOS系統UI系統中用於構建圖像對象的類,可是其中只有圖像數據,實際上一個圖片文件中存儲的除了圖片數據外,還有一些地理位置、設備類型、時間等信息,除此以外,一個圖片文件中可能存儲的也不僅一張圖像(例如gif文件)。CGImageSource就是這樣的一個抽象圖片數據示例,從其中能夠獲取到咱們所關心的全部數據。框架

    讀取圖片文件數據,並將其展現在視圖的簡單代碼示例以下:ide

//獲取圖片文件路徑
NSString * path = [[NSBundle mainBundle]pathForResource:@"timg" ofType:@"jpeg"];
NSURL * url = [NSURL fileURLWithPath:path];
CGImageRef myImage = NULL;
CGImageSourceRef myImageSource;
//經過文件路徑建立CGImageSource對象
myImageSource = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
//獲取第一張圖片
myImage = CGImageSourceCreateImageAtIndex(myImageSource,
                                          0,
                                          NULL);
CFRelease(myImageSource);
UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
image.image = [UIImage imageWithCGImage:myImage];
[self.view addSubview:image];

上面的示例代碼採用的是本地的一個素材文件,固然經過網絡圖片連接也是能夠建立CGImageSource獨享的。除了經過URL連接的方式建立對象,ImageIO框架中還提供了兩種方法,解析以下:函數

//經過數據提供器建立CGImageSource對象
/*
CGDataProviderRef是CoreGraphics框架中的一個數據讀取類,其也能夠經過Data數據,URL和文件名來建立
*/
CGImageSourceRef __nullable CGImageSourceCreateWithDataProvider(CGDataProviderRef __nonnull provider, CFDictionaryRef __nullable options);
//經過Data數據建立CGImageSource對象
CGImageSourceRef __nullable CGImageSourceCreateWithData(CFDataRef __nonnull data, CFDictionaryRef __nullable options);

須要注意,上面所提到的全部建立CGImageSource的方法中均可以傳入一個CFDictionaryRef類型的字典,能夠配置的鍵值意義以下:oop

/*
設置一個預期的圖片文件格式,須要設置爲字符串類型的值
*/
const CFStringRef kCGImageSourceTypeIdentifierHint;
/*
設置是否以解碼的方式讀取圖片數據 默認爲kCFBooleanTrue
若是設置爲true,在讀取數據時就進行解碼 若是爲false 則在渲染時才進行解碼
*/
const CFStringRef kCGImageSourceShouldCache;
/*
返回CGImage對象時是否容許使用浮點值 默認爲kCFBooleanFalse
*/
const CFStringRef kCGImageSourceShouldAllowFloa;
/*
設置若是不存在縮略圖則建立一個縮略圖,縮略圖的尺寸受開發者設置影響,若是不設置尺寸極限,則爲圖片自己大小
默認爲kCFBooleanFalse
*/
const CFStringRef kCGImageSourceCreateThumbnailFromImageIfAbsent;
/*
設置是否建立縮略圖,不管原圖像有沒有包含縮略圖kCFBooleanFalse
*/
const CFStringRef kCGImageSourceCreateThumbnailFromImageAlways;
/*
設置縮略圖的寬高尺寸 須要設置爲CFNumber值
*/
const CFStringRef kCGImageSourceThumbnailMaxPixelSize;
/*
設置縮略圖是否進行Transfrom變換
*/
const CFStringRef kCGImageSourceCreateThumbnailWithTransform;

CGImageSource類中其餘方法解析以下:

//獲取CGImageSource類在CoreFundation框架中的id
CFTypeID CGImageSourceGetTypeID (void);
//獲取所支持的圖片格式數組
CFArrayRef __nonnull CGImageSourceCopyTypeIdentifiers(void);
//獲取CGImageSource對象的圖片格式
CFStringRef __nullable CGImageSourceGetType(CGImageSourceRef __nonnull isrc);
//獲取CGImageSource中的圖片張數 不包括縮略圖
size_t CGImageSourceGetCount(CGImageSourceRef __nonnull isrc);
//獲取CGImageSource的文件信息
/*
字典參數可配置的鍵值對與建立CGImageSource所傳參數意義一致
返回的字典中的鍵值意義後面介紹
*/
CFDictionaryRef __nullable CGImageSourceCopyProperties(CGImageSourceRef __nonnull isrc, CFDictionaryRef __nullable options);
//獲取CGImageSource中某個圖像的附加數據
/*
index參數設置獲取第幾張圖像 options參數可配置的鍵值對與建立CGImageSource所傳參數意義一致
返回的字典中的鍵值意義後面介紹
*/
CFDictionaryRef __nullable CGImageSourceCopyPropertiesAtIndex(CGImageSourceRef __nonnull isrc, size_t index, CFDictionaryRef __nullable options);
//獲取圖片的元數據信息 CGImageMetadataRef類是圖像原數據的抽象
CGImageMetadataRef __nullable CGImageSourceCopyMetadataAtIndex (CGImageSourceRef __nonnull isrc, size_t index, CFDictionaryRef __nullable options);
//獲取CGImageSource中的圖片數據
CGImageRef __nullable CGImageSourceCreateImageAtIndex(CGImageSourceRef __nonnull isrc, size_t index, CFDictionaryRef __nullable options);
//刪除一個指定索引圖像的緩存
void CGImageSourceRemoveCacheAtIndex(CGImageSourceRef __nonnull isrc, size_t index);
//獲取某一幀圖片的縮略圖
CGImageRef __nullable CGImageSourceCreateThumbnailAtIndex(CGImageSourceRef __nonnull isrc, size_t index, CFDictionaryRef __nullable options);
//建立一個空的CGImageSource容器,逐步加載大圖片
CGImageSourceRef __nonnull CGImageSourceCreateIncremental(CFDictionaryRef __nullable options);
//使用新的數據更新CGImageSource容器
void CGImageSourceUpdateData(CGImageSourceRef __nonnull isrc, CFDataRef __nonnull data, bool final);
//更新數據提供器來填充CGImageSource容器
void CGImageSourceUpdateDataProvider(CGImageSourceRef __nonnull isrc, CGDataProviderRef __nonnull provider, bool final);
//獲取當前CGImageSource的狀態
/*
CGImageSourceStatus枚舉意義:
typedef CF_ENUM(int32_t, CGImageSourceStatus) {
    kCGImageStatusUnexpectedEOF = -5, //文件結尾出錯
    kCGImageStatusInvalidData = -4,   //數據無效
    kCGImageStatusUnknownType = -3,   //未知的圖片類型
    kCGImageStatusReadingHeader = -2, //讀標題過程當中
    kCGImageStatusIncomplete = -1,    //操做不完整
    kCGImageStatusComplete = 0        //操做完整
};
*/
CGImageSourceStatus CGImageSourceGetStatus(CGImageSourceRef __nonnull isrc);
//同上,獲取某一個圖片的狀態
CGImageSourceStatus CGImageSourceGetStatusAtIndex(CGImageSourceRef __nonnull isrc, size_t index);

3、CGImageDestination詳解

    CGImageSource是圖片文件數據的抽象對象,而CGImageDestination的做用則是將抽象的圖片數據寫入指定的目標中。將圖片寫成文件示例以下:

//建立存儲路徑
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *newPath = [paths.firstObject stringByAppendingPathComponent:[NSString stringWithFormat:@"image.png"]];
CFURLRef URL =  CFURLCreateWithFileSystemPath (
                                   kCFAllocatorDefault,
                                   (CFStringRef)newPath,
                                   kCFURLPOSIXPathStyle, 
                                   false);
//建立CGImageDestination對象
CGImageDestinationRef myImageDest = CGImageDestinationCreateWithURL(URL,CFSTR("public.png"), 1, NULL);
UIImage * image = [UIImage imageNamed:@"timg.jpeg"];
//寫入圖片
CGImageDestinationAddImage(myImageDest, image.CGImage, NULL);
CGImageDestinationFinalize(myImageDest);
CFRelease(myImageDest);

一樣,除了能夠直接將圖片數據寫入url外,也能夠Data數據或數據消費器,方法以下:

//將圖片數據寫入數據消費者
CGImageDestinationRef __nullable CGImageDestinationCreateWithDataConsumer(CGDataConsumerRef __nonnull consumer, CFStringRef __nonnull type, size_t count, CFDictionaryRef __nullable options);
//將圖片數據寫入Data
CGImageDestinationRef __nullable CGImageDestinationCreateWithData(CFMutableDataRef __nonnull data, CFStringRef __nonnull type, size_t count, CFDictionaryRef __nullable options);

須要注意,上面方法的type參數設置寫入數據的文件格式,必須爲ImageIO框架所支持的格式,前面有方法能夠獲取全部支持的格式,還有一點,這3個寫入方法的中options參數目前並無什麼做用,其是留給將來使用的,目前傳入NULL便可。

CGImageDestination類中的其餘方法解析以下:

//獲取CGImageDestination的CFTypeID
CFTypeID CGImageDestinationGetTypeID(void);
//獲取CGImageDestination所支持的圖片文件類型
/*
目前支持以下:iOS10.1
 (
    "public.jpeg",
    "public.png",
    "com.compuserve.gif",
    "public.tiff",
    "public.jpeg-2000",
    "com.microsoft.ico",
    "com.microsoft.bmp",
    "com.adobe.photoshop-image",
    "com.adobe.pdf",
    "com.truevision.tga-image",
    "com.ilm.openexr-image",
    "public.pbm",
    "public.pvr",
    "org.khronos.astc",
    "org.khronos.ktx",
    "com.microsoft.dds",
    "com.apple.rjpeg"
)
*/
CFArrayRef __nonnull CGImageDestinationCopyTypeIdentifiers(void);
//設置圖片文件屬性
/*
能夠設置的鍵值對意義以下:
const CFStringRef kCGImageDestinationLossyCompressionQuality; //設置壓縮質量 0-1之間的cfnumberref值
const CFStringRef kCGImageDestinationBackgroundColor;  //將圖片數據寫爲無alpha通道時的默認背景色 cgcolor值
*/
void CGImageDestinationSetProperties(CGImageDestinationRef __nonnull idst, CFDictionaryRef __nullable properties);
//向CGImageDestination中添加一張圖片 其中的option參數意義和上面一致,設置此圖片的質量與無alpha默認背景色
void CGImageDestinationAddImage(CGImageDestinationRef __nonnull idst, CGImageRef __nonnull image, CFDictionaryRef __nullable properties);
//經過CGImageSource對象來向CGImageDestination中添加圖片
void CGImageDestinationAddImageFromSource(CGImageDestinationRef __nonnull idst, CGImageSourceRef __nonnull isrc, size_t index, CFDictionaryRef __nullable properties);
//進行寫入操做 執行此方法後 不能夠在寫入其餘信息
bool CGImageDestinationFinalize(CGImageDestinationRef __nonnull idst);
//添加圖片元信息
void CGImageDestinationAddImageAndMetadata(CGImageDestinationRef __nonnull idst, CGImageRef __nonnull image, CGImageMetadataRef __nullable metadata, CFDictionaryRef __nullable options);
//將CGImageSource信息拷貝進CGImageDestination
/*
options參數能夠用來添加元信息
*/
bool CGImageDestinationCopyImageSource(CGImageDestinationRef __nonnull idst, CGImageSourceRef __nonnull isrc, CFDictionaryRef __nullable options, __nullable CFErrorRef * __nullable err);

上面列舉的方法中,CGImageDestinationCopyImageSource()方法中的options參數能夠添加一些圖片的元信息,能夠設置的鍵值對意義以下:

//設置元信息 須要設置爲CGImageMetadataRef對象
const CFStringRef kCGImageDestinationMetadata;
//是否將CGImageSource的元信息信息合併操做 默認爲kCFBooleanFalse
const CFStringRef kCGImageDestinationMergeMetadata;
//XMP數據是否不被寫入 默認爲kCFBooleanFalse
const CFStringRef kCGImageMetadataShouldExcludeXMP;
//GPS信息是否不被寫入 默認爲kCFBooleanFalse
const CFStringRef kCGImageMetadataShouldExcludeGPS;
//更新元數據的時間值 須要設置爲CFStringRef或者CFDateRef
const CFStringRef kCGImageDestinationDateTime;
//更新元數據的方向值 須要設置爲NSNumber1-8
const CFStringRef kCGImageDestinationOrientation;

4、關於CGImageMetadata

    前面咱們不少次提到元數據,CGImageMetadata類就是元數據的抽象,其中封裝了一些方法供開發者讀取或寫入元數據信息。奇怪的是Apple的官方文檔與API文檔中並無CGImageMetadata的介紹與解釋,博客中本部分的內容,多出自個人理解,有疏漏和不對的地方,清楚的朋友能夠指點與建議。

    前邊介紹,CGImageSource中有獲取圖片元數據的方法,CGImageDestination中也有寫入圖片元數據的方法,元數據中抽象出的CGImageMetadataTag是對具體數據內容的封裝。CGImageMetadata解析以下:

//獲取CGImageMetadata類的CFTypeID
CFTypeID CGImageMetadataGetTypeID(void);
//建立一個空的可變的CGImageMetadata對象
CGMutableImageMetadataRef __nonnull CGImageMetadataCreateMutable(void);
//拷貝一個可變的CGImageMetadata對象
CGMutableImageMetadataRef __nullable CGImageMetadataCreateMutableCopy(CGImageMetadataRef __nonnull metadata);
//獲取CGImageMetadataTag類的CFTypeID
CFTypeID CGImageMetadataTagGetTypeID(void);
//建立一個CGImageMetadataTag對象
/*
這個方法比較複雜
xmlns參數設置命名空間
prefix參數設置命名空間的縮寫或前綴
name參數設置CGImageMetadataTag的名稱
type參數設置CGImageMetadataTag對應值的類型
value參數設置CGImageMetadataTag的對應值
*/
CGImageMetadataTagRef __nullable CGImageMetadataTagCreate (CFStringRef __nonnull xmlns, CFStringRef __nullable prefix, CFStringRef __nonnull name, CGImageMetadataType type, CFTypeRef __nonnull value);

上面建立CGImageMetadataTag的方法中,xmlns設置命名空間,必須使用一個預約義的命名空間或者自定義的命名空間,對於自定義的命名空間,必須遵照Adobe的XMP規範。一些共用的命名空間定義以下:

//Exif命名空間
const CFStringRef  kCGImageMetadataNamespaceExif;
//ExifAux命名空間
const CFStringRef  kCGImageMetadataNamespaceExifAux;
//ExifEX命名空間
const CFStringRef  kCGImageMetadataNamespaceExifEX;
//DublineCore命名空間
const CFStringRef  kCGImageMetadataNamespaceDublinCore;
//IPTCCore命名空間
const CFStringRef  kCGImageMetadataNamespaceIPTCCore;
//Photoshop命名空間
const CFStringRef  kCGImageMetadataNamespacePhotoshop;
//TIFF命名空間
const CFStringRef  kCGImageMetadataNamespaceTIFF;
//XMPBasic命名空間
const CFStringRef  kCGImageMetadataNamespaceXMPBasic;
//XMPRights命名空間
const CFStringRef  kCGImageMetadataNamespaceXMPRights;

上面建立CGImageMetadataTag的方法中prefix設置命名空間縮寫或前綴,一樣一些公用的前綴定義以下:

//Exif命名空間前綴
const CFStringRef  kCGImageMetadataPrefixExif;
//ExifAux命名空間前綴
const CFStringRef  kCGImageMetadataPrefixExifAux;
//ExifEX命名空間前綴
const CFStringRef  kCGImageMetadataPrefixExifEX;
//DublinCore命名空間前綴
const CFStringRef  kCGImageMetadataPrefixDublinCore;
//IPCCore命名空間前綴
const CFStringRef  kCGImageMetadataPrefixIPTCCore;
//Photoshop命名空間前綴
const CFStringRef  kCGImageMetadataPrefixPhotoshop;
//TIFF命名空間前綴
const CFStringRef  kCGImageMetadataPrefixTIFF;
//XMPBasic命名空間前綴
const CFStringRef  kCGImageMetadataPrefixXMPBasic;
//XMPRights命名空間前綴
const CFStringRef  kCGImageMetadataPrefixXMPRights;

上面建立CGImageMetadataTag的方法中type設置對應值的類型,其是一個CGImageMetadataType類型的枚舉,意義以下:

typedef CF_ENUM(int32_t, CGImageMetadataType) {
    //無效的數據類型
    kCGImageMetadataTypeInvalid = -1,
    //基本的CFType類型
    kCGImageMetadataTypeDefault = 0,
    //字符串類型
    kCGImageMetadataTypeString = 1,
    //無需集合類型
    kCGImageMetadataTypeArrayUnordered = 2,
    //有序集合類型
    kCGImageMetadataTypeArrayOrdered = 3,
    //有序陣列
    kCGImageMetadataTypeAlternateArray = 4,
    //特殊的數組 其中元素進行不一樣的本地化
    kCGImageMetadataTypeAlternateText = 5,
    //結構類型 如字典
    kCGImageMetadataTypeStructure = 6
};

獲取到CGImageMetadataTag後,能夠經過以下方法來獲取其中封裝的信息:

//獲取標籤的命名空間
CFStringRef __nullable CGImageMetadataTagCopyNamespace(CGImageMetadataTagRef __nonnull tag);
//獲取標籤的命名空間前綴
CFStringRef __nullable CGImageMetadataTagCopyPrefix(CGImageMetadataTagRef __nonnull tag);
//獲取標籤名稱
CFStringRef __nullable CGImageMetadataTagCopyName(CGImageMetadataTagRef __nonnull tag);
//獲取標籤的值
CFTypeRef __nullable CGImageMetadataTagCopyValue(CGImageMetadataTagRef __nonnull tag);
//獲取標籤值的類型
CGImageMetadataType CGImageMetadataTagGetType(CGImageMetadataTagRef __nonnull tag);
//獲取標籤的Qualifier數組
CFArrayRef __nullable CGImageMetadataTagCopyQualifiers(CGImageMetadataTagRef __nonnull tag);

下面這些方法用於向CGImageMetadata中添加標籤或者獲取標籤:

//獲取CGImageMetadata中的全部標籤
CFArrayRef __nullable CGImageMetadataCopyTags(CGImageMetadataRef __nonnull metadata);
//經過路徑查找特殊的標籤
CGImageMetadataTagRef __nullable CGImageMetadataCopyTagWithPath(CGImageMetadataRef __nonnull metadata, CGImageMetadataTagRef __nullable parent, CFStringRef __nonnull path);
//經過路徑查找特殊標籤的值
 CFStringRef __nullable CGImageMetadataCopyStringValueWithPath(CGImageMetadataRef __nonnull metadata, CGImageMetadataTagRef __nullable parent, CFStringRef __nonnull path);
//爲一個前綴註冊一個命名空間
bool CGImageMetadataRegisterNamespaceForPrefix(CGMutableImageMetadataRef __nonnull metadata, CFStringRef __nonnull xmlns, CFStringRef __nonnull prefix, __nullable CFErrorRef * __nullable err);
//經過路徑爲CGImageMetadata設置標籤
bool CGImageMetadataSetTagWithPath(CGMutableImageMetadataRef __nonnull metadata, CGImageMetadataTagRef __nullable parent, CFStringRef __nonnull path, CGImageMetadataTagRef __nonnull tag);
//經過路徑爲CGImageMetadata設置標籤的值
bool CGImageMetadataSetValueWithPath(CGMutableImageMetadataRef __nonnull metadata, CGImageMetadataTagRef __nullable parent, CFStringRef __nonnull path, CFTypeRef __nonnull value);
//經過路徑移除一個標籤
bool CGImageMetadataRemoveTagWithPath(CGMutableImageMetadataRef __nonnull metadata,  CGImageMetadataTagRef __nullable parent, CFStringRef __nonnull path);
//對標籤進行枚舉
void CGImageMetadataEnumerateTagsUsingBlock(CGImageMetadataRef __nonnull metadata, CFStringRef __nullable rootPath, CFDictionaryRef __nullable options, CGImageMetadataTagBlock __nonnull block);

5、CGImageProperties中定義的字典意義

    前面提到的CGImageSourceCopyProperties方法與CGImageSourceCopyPropertiesAtIndex方法都會返回一個字典,字典中可能包含以下有意義的鍵:

//TIFF信息字典
const CFStringRef kCGImagePropertyTIFFDictionary;
/GIF信息字典
const CFStringRef kCGImagePropertyGIFDictionary;
//JFIF信息字典
const CFStringRef kCGImagePropertyJFIFDictionary;
//EXif信息字典
const CFStringRef kCGImagePropertyExifDictionary;
//PNG信息字典
const CFStringRef kCGImagePropertyPNGDictionary;
//IPTC信息字典
const CFStringRef kCGImagePropertyIPTCDictionary;
//GPS信息字典
const CFStringRef kCGImagePropertyGPSDictionary;
//原始信息字典
const CFStringRef kCGImagePropertyRawDictionary;
//CIFF信息字典
const CFStringRef kCGImagePropertyCIFFDictionary;
//佳能相機信息字典
const CFStringRef kCGImagePropertyMakerCanonDictionary;
//尼康相機信息字典
const CFStringRef kCGImagePropertyMakerNikonDictionary;
//柯尼卡相機信息字典
const CFStringRef kCGImagePropertyMakerMinoltaDictionary;
//富士相機信息字典
const CFStringRef kCGImagePropertyMakerFujiDictionary;
//奧林巴斯相機信息字典
const CFStringRef kCGImagePropertyMakerOlympusDictionary;
//賓得相機信息字典
const CFStringRef kCGImagePropertyMakerPentaxDictionary;
//對應Photoshop相片的信息字典
const CFStringRef kCGImageProperty8BIMDictionary;
//NDG信息字典
const CFStringRef kCGImagePropertyDNGDictionary ;
//ExifAux信息字典
const CFStringRef kCGImagePropertyExifAuxDictionary;
//OpenEXR信息字典
const CFStringRef kCGImagePropertyOpenEXRDictionary;
//Apple相機信息字典
const CFStringRef kCGImagePropertyMakerAppleDictionary ;

CGImageSourceCopyProperties方法返回的字典中還可能會有以下一個特殊的鍵:

//對應文件大小
const CFStringRef kCGImagePropertyFileSize;

CGImageSourceCopyPropertiesAtIndex方法中可能包含的特殊鍵:

//像素高度
const CFStringRef kCGImagePropertyPixelHeight;
//像素寬度
const CFStringRef kCGImagePropertyPixelWidth;
//DPI高度
const CFStringRef kCGImagePropertyDPIHeight;
//DPI寬度
const CFStringRef kCGImagePropertyDPIWidth;
//顏色位數
const CFStringRef kCGImagePropertyDepth;
//圖片的顯示方向
/*
對應Number值
 *   1  =  左上到右下.  
 *   2  =  右上到左下.  
 *   3  =  右下到左上.
 *   4  =  左下到右上.  
 *   5  =  行列置換 左上到右下.  
 *   6  =  行列置換 右上到左下.  
 *   7  =  行列置換 右下到左上.  
 *   8  =  行列置換 左下到右上.
*/
const CFStringRef kCGImagePropertyOrientation;
//顏色是否支持浮點數
const CFStringRef kCGImagePropertyIsFloat;
//圖像是否包含像素樣本
const CFStringRef kCGImagePropertyIsIndexed;
//圖像是否包含alpha通道
const CFStringRef kCGImagePropertyHasAlpha;
//圖像的顏色模式
const CFStringRef kCGImagePropertyColorModel;
//嵌入圖片的ICC配置文件名稱
const CFStringRef kCGImagePropertyProfileName;

kCGImagePropertyColorModel鍵可返回的值有以下幾種定義:

//RBG模式
const CFStringRef kCGImagePropertyColorModelRGB;
//Gray模式
const CFStringRef kCGImagePropertyColorModelGray;
//CMYK模式
const CFStringRef kCGImagePropertyColorModelCMYK;
//Lab模式
const CFStringRef kCGImagePropertyColorModelLab;

kCGImagePropertyTIFFDictionary鍵可返回的值定義以下:

//圖片數據壓縮方案
const CFStringRef kCGImagePropertyTIFFCompression;
//圖片數據的色彩空間
const CFStringRef kCGImagePropertyTIFFPhotometricInterpretation;
//文檔名稱
const CFStringRef kCGImagePropertyTIFFDocumentName;
//圖片描述
const CFStringRef kCGImagePropertyTIFFImageDescription;
//相機設備名
const CFStringRef kCGImagePropertyTIFFMake;
//相機設備模式
const CFStringRef kCGImagePropertyTIFFModel;
//圖片方向
const CFStringRef kCGImagePropertyTIFFOrientation;
//橫向每一個分辨位的像素數
const CFStringRef kCGImagePropertyTIFFXResolution;
//縱向每一個分辨位的像素數
const CFStringRef kCGImagePropertyTIFFYResolution;
//分辨率單位
const CFStringRef kCGImagePropertyTIFFResolutionUnit;
//建立圖像的軟件名稱和版本
const CFStringRef kCGImagePropertyTIFFSoftware;
//transform函數
const CFStringRef kCGImagePropertyTIFFTransferFunction;
//日期時間
const CFStringRef kCGImagePropertyTIFFDateTime;
//做者
const CFStringRef kCGImagePropertyTIFFArtist;
//建立圖片的電腦系統
const CFStringRef kCGImagePropertyTIFFHostComputer;
//公司信息
const CFStringRef kCGImagePropertyTIFFCopyright;
//圖片的白點
const CFStringRef kCGImagePropertyTIFFWhitePoint;
//圖像的原色色度
const CFStringRef kCGImagePropertyTIFFPrimaryChromaticities;
//圖片的瓦片寬度
const CFStringRef kCGImagePropertyTIFFTileWidth;
//圖片的瓦片高度
const CFStringRef kCGImagePropertyTIFFTileLength;

kCGImagePropertyJFIFDictionary對應的字典中可能包含以下意義的鍵:

//JFIF版本
const CFStringRef kCGImagePropertyJFIFVersion;
//橫向像素密度
const CFStringRef kCGImagePropertyJFIFXDensity;
//縱向像素密度
const CFStringRef kCGImagePropertyJFIFYDensity;
//像素密度單元
const CFStringRef kCGImagePropertyJFIFDensityUnit;
//是不是高質量圖像版本
const CFStringRef kCGImagePropertyJFIFIsProgressive;

kCGImagePropertyExifDictionary對應的字典中可能包含以下意義的鍵 :

//曝光時間
const CFStringRef kCGImagePropertyExifExposureTime;
//ExifNumber
const CFStringRef kCGImagePropertyExifFNumber;
//曝光程序
const CFStringRef kCGImagePropertyExifExposureProgram;
//每一個通道的光譜靈敏度
const CFStringRef kCGImagePropertyExifSpectralSensitivity;
//ISO速度等級
const CFStringRef kCGImagePropertyExifISOSpeedRatings;
//ExifOECF
const CFStringRef kCGImagePropertyExifOECF;
//靈敏類型
const CFStringRef kCGImagePropertyExifSensitivityType;
//輸出靈敏標準
const CFStringRef kCGImagePropertyExifStandardOutputSensitivity;
//推薦曝光指數
const CFStringRef kCGImagePropertyExifRecommendedExposureIndex;
//ISO速率
const CFStringRef kCGImagePropertyExifISOSpeed;
const CFStringRef kCGImagePropertyExifISOSpeedLatitudeyyy;
const CFStringRef kCGImagePropertyExifISOSpeedLatitudezzz;
//Exif版本
const CFStringRef kCGImagePropertyExifVersion;
//原始日期時間
const CFStringRef kCGImagePropertyExifDateTimeOriginal;
//數字化日期時間
const CFStringRef kCGImagePropertyExifDateTimeDigitized;
//壓縮配置
const CFStringRef kCGImagePropertyExifComponentsConfiguration;
//壓縮模式像素位
const CFStringRef kCGImagePropertyExifCompressedBitsPerPixel;
//快門速度值
const CFStringRef kCGImagePropertyExifShutterSpeedValue;
//孔徑值
const CFStringRef kCGImagePropertyExifApertureValue;
//亮度值
const CFStringRef kCGImagePropertyExifBrightnessValue;
//曝光誤差值
const CFStringRef kCGImagePropertyExifExposureBiasValue;
//最大光圈值
const CFStringRef kCGImagePropertyExifMaxApertureValue;
//距離
const CFStringRef kCGImagePropertyExifSubjectDistance;
//測光模式
const CFStringRef kCGImagePropertyExifMeteringMode;
//光源
const CFStringRef kCGImagePropertyExifLightSource;
//拍攝時的閃光狀態
const CFStringRef kCGImagePropertyExifFlash;
//焦距
const CFStringRef kCGImagePropertyExifFocalLength;
//主體區域
const CFStringRef kCGImagePropertyExifSubjectArea;
//相機制造商指定的信息
const CFStringRef kCGImagePropertyExifMakerNote;
//用戶信息
const CFStringRef kCGImagePropertyExifUserComment;
//日期和時間標記的秒分數
const CFStringRef kCGImagePropertyExifSubsecTime;
//原始時間
const CFStringRef kCGImagePropertyExifSubsecTimeOriginal;
//數字時間
const CFStringRef kCGImagePropertyExifSubsecTimeDigitized;
//FlashPix版本信息
const CFStringRef kCGImagePropertyExifFlashPixVersion;
//色彩空間
const CFStringRef kCGImagePropertyExifColorSpace;
//X方向像素
const CFStringRef kCGImagePropertyExifPixelXDimension;
//Y方向像素
const CFStringRef kCGImagePropertyExifPixelYDimension;
//與圖像相關的聲音文件
const CFStringRef kCGImagePropertyExifRelatedSoundFile;
//FlashEnergy
const CFStringRef kCGImagePropertyExifFlashEnergy;
//FrequencyResponse
const CFStringRef kCGImagePropertyExifSpatialFrequencyResponse;
//像素數目
const CFStringRef kCGImagePropertyExifFocalPlaneXResolution;
const CFStringRef kCGImagePropertyExifFocalPlaneYResolution;
const CFStringRef kCGImagePropertyExifFocalPlaneResolutionUnit;
//圖像主體的位置
const CFStringRef kCGImagePropertyExifSubjectLocation;
//選擇的曝光指數
const CFStringRef kCGImagePropertyExifExposureIndex;
//傳感器類型
const CFStringRef kCGImagePropertyExifSensingMethod;
//圖像文件源
const CFStringRef kCGImagePropertyExifFileSource;
//場景類型
const CFStringRef kCGImagePropertyExifSceneType;
//CFA模塊
const CFStringRef kCGImagePropertyExifCFAPattern;
//對圖像數據進行特殊渲染
const CFStringRef kCGImagePropertyExifCustomRendered;
//曝光模式設置
const CFStringRef kCGImagePropertyExifExposureMode;
//白平衡模式
const CFStringRef kCGImagePropertyExifWhiteBalance;
//數字變焦比
const CFStringRef kCGImagePropertyExifDigitalZoomRatio;
//35毫米膠片的等效焦距
const CFStringRef kCGImagePropertyExifFocalLenIn35mmFilm;
//場景捕捉類型(標準,景觀,肖像,夜晚)
const CFStringRef kCGImagePropertyExifSceneCaptureType;
//圖像增益
const CFStringRef kCGImagePropertyExifGainControl;
//圖像對比度
const CFStringRef kCGImagePropertyExifContrast;
//圖像飽和度
const CFStringRef kCGImagePropertyExifSaturation;
//圖像銳度
const CFStringRef kCGImagePropertyExifSharpness;
//拍攝條件
const CFStringRef kCGImagePropertyExifDeviceSettingDescription;
//主體距離
const CFStringRef kCGImagePropertyExifSubjectDistRange;
//圖像的惟一標識
const CFStringRef kCGImagePropertyExifImageUniqueID;
//相機全部者
const CFStringRef kCGImagePropertyExifCameraOwnerName;
//相機序列號
const CFStringRef kCGImagePropertyExifBodySerialNumber;
//透鏡規格信息
const CFStringRef kCGImagePropertyExifLensSpecification;
//透鏡製造商名稱
const CFStringRef kCGImagePropertyExifLensMake;
//透鏡模式
const CFStringRef kCGImagePropertyExifLensModel;
//透鏡序列號
const CFStringRef kCGImagePropertyExifLensSerialNumber;
//伽馬設置
const CFStringRef kCGImagePropertyExifGamma;

kCGImagePropertyExifAuxDictionary對應的字典中可能包含的鍵定義以下:

//鏡頭信息
const CFStringRef kCGImagePropertyExifAuxLensInfo;
//鏡頭模式
const CFStringRef kCGImagePropertyExifAuxLensModel;
//序列號
const CFStringRef kCGImagePropertyExifAuxSerialNumber;
//鏡頭ID
const CFStringRef kCGImagePropertyExifAuxLensID;
//鏡頭序列號
const CFStringRef kCGImagePropertyExifAuxLensSerialNumber;
//圖片編號
const CFStringRef kCGImagePropertyExifAuxImageNumber;
//閃光補償
const CFStringRef kCGImagePropertyExifAuxFlashCompensation;
//全部者名稱
const CFStringRef kCGImagePropertyExifAuxOwnerName;
//固件信息
const CFStringRef kCGImagePropertyExifAuxFirmware;

kCGImagePropertyGIFDictionary對應的字典中可能包含的鍵定義以下:

//動畫循環次數
const CFStringRef kCGImagePropertyGIFLoopCount;
//兩幀之間的延時
const CFStringRef kCGImagePropertyGIFDelayTime;
//顏色Map
const CFStringRef kCGImagePropertyGIFImageColorMap;
const CFStringRef kCGImagePropertyGIFHasGlobalColorMap;
//兩幀之間的延時
const CFStringRef kCGImagePropertyGIFUnclampedDelayTime;

kCGImagePropertyPNGDictionary對應的字典中可能包含的鍵定義以下:

//PNG伽馬值
const CFStringRef kCGImagePropertyPNGGamma;
//混合類型
const CFStringRef kCGImagePropertyPNGInterlaceType;
//X方向像素數
const CFStringRef kCGImagePropertyPNGXPixelsPerMeter;
//Y方向像素數
const CFStringRef kCGImagePropertyPNGYPixelsPerMeter;
//RGB意圖
const CFStringRef kCGImagePropertyPNGsRGBIntent;
//色度
const CFStringRef kCGImagePropertyPNGChromaticities;
//做者
const CFStringRef kCGImagePropertyPNGAuthor;
//公司
const CFStringRef kCGImagePropertyPNGCopyright;
//建立時間
const CFStringRef kCGImagePropertyPNGCreationTime;
//描述
const CFStringRef kCGImagePropertyPNGDescription;
//最後修改日期時間
const CFStringRef kCGImagePropertyPNGModificationTime;
//軟件
const CFStringRef kCGImagePropertyPNGSoftware;
//標題
const CFStringRef kCGImagePropertyPNGTitle;
//動畫循環次數
const CFStringRef kCGImagePropertyAPNGLoopCount;
//兩幀之間的延時
const CFStringRef kCGImagePropertyAPNGDelayTime;
const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime;

kCGImagePropertyGPSDictionary對應的字典中可能包含的鍵定義以下:

//GPS版本
const CFStringRef kCGImagePropertyGPSVersion;
//緯度是南緯或北緯
const CFStringRef kCGImagePropertyGPSLatitudeRef;
//緯度
const CFStringRef kCGImagePropertyGPSLatitude;
//經度是東經或西經
const CFStringRef kCGImagePropertyGPSLongitudeRef;
//經度
const CFStringRef kCGImagePropertyGPSLongitude;
//海拔標準
const CFStringRef kCGImagePropertyGPSAltitudeRef;
//海拔高度
const CFStringRef kCGImagePropertyGPSAltitude;
//時間戳
const CFStringRef kCGImagePropertyGPSTimeStamp;
//測量GPS的衛星
const CFStringRef kCGImagePropertyGPSSatellites;
//GPS狀態
const CFStringRef kCGImagePropertyGPSStatus;
//測量模式
const CFStringRef kCGImagePropertyGPSMeasureMode;
//精度數據
const CFStringRef kCGImagePropertyGPSDOP;
//速度標準
const CFStringRef kCGImagePropertyGPSSpeedRef;
//速度
const CFStringRef kCGImagePropertyGPSSpeed;
//運動方向參考
const CFStringRef kCGImagePropertyGPSTrackRef;
//運動方向
const CFStringRef kCGImagePropertyGPSTrack;
//位置方向參考
const CFStringRef kCGImagePropertyGPSImgDirectionRef;
//位置方向
const CFStringRef kCGImagePropertyGPSImgDirection;
//地圖測量數據
const CFStringRef kCGImagePropertyGPSMapDatum;
//地理緯度南緯或北緯
const CFStringRef kCGImagePropertyGPSDestLatitudeRef;
//地理緯度
const CFStringRef kCGImagePropertyGPSDestLatitude;
//地理經度 東經或西經
const CFStringRef kCGImagePropertyGPSDestLongitudeRef;
//地理經度
const CFStringRef kCGImagePropertyGPSDestLongitude;
//方位參照
const CFStringRef kCGImagePropertyGPSDestBearingRef;
//地理方位
const CFStringRef kCGImagePropertyGPSDestBearing;
//距離參照
const CFStringRef kCGImagePropertyGPSDestDistanceRef;
//距離
const CFStringRef kCGImagePropertyGPSDestDistance;
//查找地理位置的方法
const CFStringRef kCGImagePropertyGPSProcessingMethod;
//GPS地區名
const CFStringRef kCGImagePropertyGPSAreaInformation;
//日期時間
const CFStringRef kCGImagePropertyGPSDateStamp;
//校訂信息
const CFStringRef kCGImagePropertyGPSDifferental;
//錯誤信息
const CFStringRef kCGImagePropertyGPSHPositioningError;

kCGImagePropertyIPTCDictionary對應的字典中可能包含的鍵定義以下:

//對象類型
const CFStringRef kCGImagePropertyIPTCObjectTypeReference;
//對象屬性
const CFStringRef kCGImagePropertyIPTCObjectAttributeReference;
//對象名稱
const CFStringRef kCGImagePropertyIPTCObjectName;
//編輯狀態
const CFStringRef kCGImagePropertyIPTCEditStatus;
//更新狀態
const CFStringRef kCGImagePropertyIPTCEditorialUpdate;
//緊急等級
const CFStringRef kCGImagePropertyIPTCUrgency;
//主體
const CFStringRef kCGImagePropertyIPTCSubjectReference;
//類別
const CFStringRef kCGImagePropertyIPTCCategory;
//補充類別
const CFStringRef kCGImagePropertyIPTCSupplementalCategory;
//Fixture標識
const CFStringRef kCGImagePropertyIPTCFixtureIdentifier;
//關鍵字
const CFStringRef kCGImagePropertyIPTCKeywords;
//內容定位碼
const CFStringRef kCGImagePropertyIPTCContentLocationCode;
//內容位置名稱
const CFStringRef kCGImagePropertyIPTCContentLocationName;
//圖像使用的最先日期
const CFStringRef kCGImagePropertyIPTCReleaseDate;
//圖像使用的最先時間
const CFStringRef kCGImagePropertyIPTCReleaseTime;
//最後一次使用日期
const CFStringRef kCGImagePropertyIPTCExpirationDate;
//最後一次使用時間
const CFStringRef kCGImagePropertyIPTCExpirationTime;
//圖像使用的特別說明
const CFStringRef kCGImagePropertyIPTCSpecialInstructions;
//建議行爲
const CFStringRef kCGImagePropertyIPTCActionAdvised;
//服務參考
const CFStringRef kCGImagePropertyIPTCReferenceService;
//日期參考
const CFStringRef kCGImagePropertyIPTCReferenceDate;
//參考碼
const CFStringRef kCGImagePropertyIPTCReferenceNumber;
//建立日期
const CFStringRef kCGImagePropertyIPTCDateCreated;
//建立時間
const CFStringRef kCGImagePropertyIPTCTimeCreated;
//數字建立日期
const CFStringRef kCGImagePropertyIPTCDigitalCreationDate;
//數字建立時間
const CFStringRef kCGImagePropertyIPTCDigitalCreationTime;
//原始程序
const CFStringRef kCGImagePropertyIPTCOriginatingProgram;
//程序版本
const CFStringRef kCGImagePropertyIPTCProgramVersion;
圖像的編輯週期(早晨,晚上或二者)。
const CFStringRef kCGImagePropertyIPTCObjectCycle;
//不想建立者名稱
const CFStringRef kCGImagePropertyIPTCByline;
//圖像建立標題
const CFStringRef kCGImagePropertyIPTCBylineTitle;
//城市信息
const CFStringRef kCGImagePropertyIPTCCity;
//城市內位置
const CFStringRef kCGImagePropertyIPTCSubLocation;
//省份
const CFStringRef kCGImagePropertyIPTCProvinceState;
//國家編碼
const CFStringRef kCGImagePropertyIPTCCountryPrimaryLocationCode;
//國家名稱
const CFStringRef kCGImagePropertyIPTCCountryPrimaryLocationName;
//OriginalTransmission參考
const CFStringRef kCGImagePropertyIPTCOriginalTransmissionReference;
//圖像內容摘要
const CFStringRef kCGImagePropertyIPTCHeadline;
//提供圖像服務的名稱
const CFStringRef kCGImagePropertyIPTCCredit;
//圖像源
const CFStringRef kCGImagePropertyIPTCSource;
//公司提示
const CFStringRef kCGImagePropertyIPTCCopyrightNotice;
//聯繫人
const CFStringRef kCGImagePropertyIPTCContact;
//描述
const CFStringRef kCGImagePropertyIPTCCaptionAbstract;
//圖像編輯者
const CFStringRef kCGImagePropertyIPTCWriterEditor;
//圖像類型
const CFStringRef kCGImagePropertyIPTCImageType;
//方向信息
const CFStringRef kCGImagePropertyIPTCImageOrientation;
//語言信息
const CFStringRef kCGImagePropertyIPTCLanguageIdentifier;
//星級
const CFStringRef kCGImagePropertyIPTCStarRating;
//聯繫人詳細信息
const CFStringRef kCGImagePropertyIPTCCreatorContactInfo;
//圖像使用權限
const CFStringRef kCGImagePropertyIPTCRightsUsageTerms;
//場景代碼
const CFStringRef kCGImagePropertyIPTCScene;

上面的kCGImagePropertyIPTCCreatorContactInfo對應的字典中鍵的定義以下:

//聯繫人城市
const CFStringRef kCGImagePropertyIPTCContactInfoCity;
//聯繫人國家
const CFStringRef kCGImagePropertyIPTCContactInfoCountry;
//聯繫人地址
const CFStringRef kCGImagePropertyIPTCContactInfoAddress;
//郵編
const CFStringRef kCGImagePropertyIPTCContactInfoPostalCode;
//省份
const CFStringRef kCGImagePropertyIPTCContactInfoStateProvince;
//電子郵件
const CFStringRef kCGImagePropertyIPTCContactInfoEmails;
//電話
const CFStringRef kCGImagePropertyIPTCContactInfoPhones;
//網址
const CFStringRef kCGImagePropertyIPTCContactInfoWebURLs;

kCGImageProperty8BIMDictionary對應的字典中可能包含的鍵定義以下:

//Photoshop文件的圖層名
const CFStringRef  kCGImageProperty8BIMLayerNames;
//版本
const CFStringRef  kCGImageProperty8BIMVersion;

kCGImagePropertyDNGDictionary對應的字典中可能包含的鍵定義以下:

//DNG版本
const CFStringRef  kCGImagePropertyDNGVersion;
//兼容的最老版本
const CFStringRef  kCGImagePropertyDNGBackwardVersion;
//攝像機模型
const CFStringRef  kCGImagePropertyDNGUniqueCameraModel;
const CFStringRef  kCGImagePropertyDNGLocalizedCameraModel;
//相機序列碼
const CFStringRef  kCGImagePropertyDNGCameraSerialNumber;
//鏡頭信息
const CFStringRef  kCGImagePropertyDNGLensInfo;
//黑度等級
const CFStringRef  kCGImagePropertyDNGBlackLevel;
//白度等級
const CFStringRef  kCGImagePropertyDNGWhiteLevel;

const CFStringRef  kCGImagePropertyDNGCalibrationIlluminant1;
const CFStringRef  kCGImagePropertyDNGCalibrationIlluminant2;
const CFStringRef  kCGImagePropertyDNGColorMatrix1;
const CFStringRef  kCGImagePropertyDNGColorMatrix2;
const CFStringRef  kCGImagePropertyDNGCameraCalibration1;
const CFStringRef  kCGImagePropertyDNGCameraCalibration2;
const CFStringRef  kCGImagePropertyDNGAsShotNeutral;
const CFStringRef  kCGImagePropertyDNGAsShotWhiteXY;
const CFStringRef  kCGImagePropertyDNGBaselineExposure;
const CFStringRef  kCGImagePropertyDNGBaselineNoise;
const CFStringRef  kCGImagePropertyDNGBaselineSharpness;
const CFStringRef  kCGImagePropertyDNGPrivateData;
const CFStringRef  kCGImagePropertyDNGCameraCalibrationSignature;
const CFStringRef  kCGImagePropertyDNGProfileCalibrationSignature;
const CFStringRef  kCGImagePropertyDNGNoiseProfile;
const CFStringRef  kCGImagePropertyDNGWarpRectilinear;
const CFStringRef  kCGImagePropertyDNGWarpFisheye;
const CFStringRef  kCGImagePropertyDNGFixVignetteRadial;

kCGImagePropertyCIFFDictionary對應的字典中可能包含的鍵定義以下:

//相機信息
const CFStringRef  kCGImagePropertyCIFFDescription;
//固件版本
const CFStringRef  kCGImagePropertyCIFFFirmware;
//全部者名稱
const CFStringRef  kCGImagePropertyCIFFOwnerName;
//圖片名
const CFStringRef  kCGImagePropertyCIFFImageName;
//圖片文件名
const CFStringRef  kCGImagePropertyCIFFImageFileName;
//曝光方式
const CFStringRef  kCGImagePropertyCIFFReleaseMethod;
//曝光時間
const CFStringRef  kCGImagePropertyCIFFReleaseTiming;
//RecordID
const CFStringRef  kCGImagePropertyCIFFRecordID;
//曝光時間
const CFStringRef  kCGImagePropertyCIFFSelfTimingTime;
//相機序列號
const CFStringRef  kCGImagePropertyCIFFCameraSerialNumber;
//圖片編碼
const CFStringRef  kCGImagePropertyCIFFImageSerialNumber;
//驅動模式
const CFStringRef  kCGImagePropertyCIFFContinuousDrive);
//焦點模式
const CFStringRef  kCGImagePropertyCIFFFocusMode;
//測量模式
const CFStringRef  kCGImagePropertyCIFFMeteringMode;
//曝光模式
const CFStringRef  kCGImagePropertyCIFFShootingMode;
//透鏡模式
const CFStringRef  kCGImagePropertyCIFFLensModel;
//最長鏡頭長度
const CFStringRef  kCGImagePropertyCIFFLensMaxMM;
//最短鏡頭長度
const CFStringRef  kCGImagePropertyCIFFLensMinMM;
//白平衡等級
const CFStringRef  kCGImagePropertyCIFFWhiteBalanceIndex;
//曝光補償
const CFStringRef  kCGImagePropertyCIFFFlashExposureComp;
//實測曝光值
const CFStringRef  kCGImagePropertyCIFFMeasuredEV);

6、ImageIO框架在實際開發中的幾個應用

1.顯示特殊格式的圖片

    在平時開發中,咱們一般使用UIImage來讀取圖片,UIImage支持的圖片包括png與jpg等,可是相似windows系統的ico圖標,UIImage默認是沒法顯示的,能夠經過ImageIO框架來在iOS系統中使用ico圖標,示例以下:

NSString * path = [[NSBundle mainBundle]pathForResource:@"image" ofType:@"ico"];
    NSURL * url = [NSURL fileURLWithPath:path];
    CGImageRef myImage = NULL;
    CGImageSourceRef myImageSource;
    CFDictionaryRef myOptions = NULL;
    myImageSource = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
    myImage = CGImageSourceCreateImageAtIndex(myImageSource,
                                              0,
                                              NULL);
    CFRelease(myImageSource);
    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    image.image = [UIImage imageWithCGImage:myImage];

2.讀取數碼相機拍攝圖片的地理位置、時間等信息

3.對相冊中圖片的地理位置,時間等信息進行自定義修改。

4.將自定義格式的圖片數據寫入本地文件。

5.展現GIF動圖

    詳情見博客:http://www.javashuo.com/article/p-rxievqbk-q.html

6.漸進渲染大圖

    漸進渲染技術在對加載大圖片時特別重要,你應該使用過地圖軟件,地圖視圖在加載時是局部進行加載,當移動或者放大時,地圖會一部分一部分的漸進進行加載,使用ImageIO框架能夠實現大圖漸進渲染的效果,通常在對大圖片進行網絡請求時,能夠獲取一部分數據就加載一部分數據,爲了便於演示,博客中使用定時器來默認網絡返回數據,代碼示例以下:

@interface ViewController ()
{
    NSMutableData * _data;
    NSData * _allData;
    NSUInteger length;
    UIImageView * _imageView;
    NSTimer * timer;
    NSInteger le;
}
@end
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _data = [[NSMutableData alloc]init];
    NSString * path = [[NSBundle mainBundle]pathForResource:@"Default-Portrait-ns@2x" ofType:@"png"];
    _allData = [NSData dataWithContentsOfFile:path];
    length = _allData.length;
    le = length/10;
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateImage) userInfo:nil repeats:YES];
    _imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_imageView];
}


-(void)updateImage{
    static int index = 0;
    if (index==10) {
        return;
    }
    NSUInteger l;
    if (index==9) {
        l=length-le*9;
    }else{
        l= le;
    }
    
    Byte by[l];
    [_allData getBytes:by range:NSMakeRange(index*le, l)];
    [_data appendBytes:by length:l];
    CGImageSourceRef myImageSource = CGImageSourceCreateWithData((CFDataRef)_data, NULL);
    CGImageRef myImage = CGImageSourceCreateImageAtIndex(myImageSource,
                                              0,
                                              NULL);
    CFRelease(myImageSource);
    
    _imageView.image = [UIImage imageWithCGImage:myImage];
    //    image.image = [UIImage imageNamed:@"image.ico"];
    index++;
}
@end

效果以下:

   

相關文章
相關標籤/搜索