天天看點

iOS中ImageIO架構詳解與應用分析(四)

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

六、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動圖

   詳情見部落格:

https://my.oschina.net/u/2340880/blog/608560

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,

   _imageView.image = [UIImage imageWithCGImage:myImage];

   //    image.image = [UIImage imageNamed:@"image.ico"];

   index++;

效果如下:

iOS中ImageIO架構詳解與應用分析(四)

繼續閱讀