我想從iPhone中獲取EXIF數據來計算亮度。我需要訪問兩個特定的NSNumber的ExifExposureTime和ExifISOSpeed轉換爲浮動,但是當我嘗試將它們轉換爲浮動我得到此錯誤:POP [11910: 207] - [__ NSCFArray floatValue]:無法識別的選擇器發送到實例0x4b48f70 2011-04-21 17:38:31.777 POP [11910:207] *終止應用程序由於未捕獲異常'NSInvalidArgumentException',原因:' - [__ NSCFArray floatValue]:無法識別的選擇發送到實例0x4b48f70'「將NSNumber轉換爲float將拋出「未捕獲的異常」NSInvalidArgumentException'「
是否有一些愚蠢的錯誤,我失蹤了?請告訴我。下面是我的代碼:
-(IBAction)getDataOne:(id)sender {
NSString *aPath = [[NSBundle mainBundle] pathForResource:@"IMG_0062" ofType:@"JPG"];
NSURL *url = [NSURL fileURLWithPath:aPath];
CGImageSourceRef sourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
NSDictionary *immutableMetadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
NSDictionary *exifDic = [immutableMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary];
NSNumber *ExifApertureValue = [exifDic objectForKey:(NSString*)kCGImagePropertyExifApertureValue];
NSNumber *ExifShutterSpeed = [exifDic objectForKey:(NSString*)kCGImagePropertyExifShutterSpeedValue];
NSNumber *ExifExposureTime = [exifDic objectForKey:(NSString*)kCGImagePropertyExifExposureTime];
NSNumber *ExifFStop = [exifDic objectForKey:(NSString*)kCGImagePropertyExifFNumber];
NSNumber *ExifISOSpeed = [exifDic objectForKey:(NSString*)kCGImagePropertyExifISOSpeedRatings];
NSLog(@"ExifApertureValue : %@ \n",ExifApertureValue);
NSLog(@"ExifShutterSpeed : %@ \n",ExifShutterSpeed);
NSLog(@"ExifExposureTime : %@ \n",ExifExposureTime);
NSLog(@"ExifFStop : %@ \n",ExifFStop);
NSLog(@"ExifISOSpeed : %@ \n",ExifISOSpeed);
float brightness, T, ISO;
float K = 12.0;
float A2 = 7.84;
T = [ExifExposureTime floatValue];
ISO = [ExifISOSpeed floatValue];
brightness = (A2 * K)/(T * ISO);
[summaryViewController imageOneSuccess];
[ExifApertureValue release];
[ExifShutterSpeed release];
[ExifExposureTime release];
[ExifFStop release];
[ExifISOSpeed release];
}
以下是在那些5條的NSLog語句輸出到顯示有存儲有效值:
2011-04-21 18:05:12.318 POP[12051:207] ExifApertureValue : 2.526069
2011-04-21 18:05:12.319 POP[12051:207] ExifShutterSpeed : 4.915926
2011-04-21 18:05:12.321 POP[12051:207] ExifExposureTime : 0.03333334
2011-04-21 18:05:12.323 POP[12051:207] ExifFStop : 2.4
2011-04-21 18:05:12.324 POP[12051:207] ExifISOSpeed : (
640
)
更新:我一直在尋找我的輸出,並注意到ExifISOSpeed是打印在那個奇怪的:
(
640
)
格式。那就是當我轉換成浮動時的問題,但是有誰知道它爲什麼以這種方式輸出?我能夠使用if語句並確定它是否大於0,因此我可以將它看作一個數字。
是否有可能是'ExifExposureTime'或'ExifISOSpeed'是零? – conmulligan 2011-04-21 22:02:15
否有正在處理的值。我更新了問題以顯示NSLOG輸出。 – tguidon 2011-04-21 22:07:06