2011-05-26 49 views
0

我已经使用的Exif标签上的JPEG文件的一些数据存储在以下方式被:的iOS:在标记APP3访问JPEG元

CGImageSourceRef source = CGImageSourceCreateWithURL(baseURL, NULL); 
NSDictionary *metadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source,0,NULL); 
NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy]autorelease]; 
NSMutableDictionary *EXIFDictionary = [[[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy]autorelease]; 
[EXIFDictionary setObject:[NSString stringWithFormat:@"%d",tag] forKey:(NSString *)kCGImagePropertyExifUserComment]; 

现在,我想用一个自定义应用程序标记(APP3在0xFFE3)而不是Exif标记。

(参见 - http://www.ozhiker.com/electronics/pjmt/jpeg_info/app_segments.html

有人能指出我在正确的方向。 PS:我为这个应用程序使用了越狱的ipad公司。

回答

0

好吧,似乎我们必须通过文件处理程序的方式来做到这一点。这是我所做的,尽管可能有更好的方法来做到这一点。

创建一个文件句柄:

NSString *filePath = currentImageObject.myFilePath; 
NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath]; 
if(!fileHandle){ 
    return; 
} 
[fileHandle seekToEndOfFile]; 
unsigned long long eofOffset = [fileHandle offsetInFile]; 

然后遍历文件内容,直到你找到想要的标签:

BOOL markerFound = NO; 
BOOL dqtFound = NO; 
while ((!markerFound) && (!dqtFound) && ([fileHandle offsetInFile] < eofOffset)) { 
     currentOffset += 1; 
     [fileHandle seekToFileOffset:currentOffset]; 
     NSData *markerData = [fileHandle readDataOfLength:1]; 
     currentOffset += 1; 
     NSInteger markerValue = (unsigned char)*(unsigned char *)[markerData bytes]; 

     if (0xe0 == markerValue) { 
      currentOffset += 14; 
      [fileHandle seekToFileOffset:currentOffset]; 

      NSData *xThumbnailData = [fileHandle readDataOfLength:1]; 
      currentOffset += 1; 
      NSData *yThumbnailData = [fileHandle readDataOfLength:1]; 
      currentOffset += 1; 
      NSInteger xThumbnail = (unsigned char)*(unsigned char *)[xThumbnailData bytes]; 
      NSInteger yThumbnail = (unsigned char)*(unsigned char *)[yThumbnailData bytes]; 
      NSInteger thumbnailSize = 3 * xThumbnail * yThumbnail; 
      currentOffset += thumbnailSize; 
      [fileHandle seekToFileOffset:currentOffset]; 
     } else if (0xe3 == markerValue) { 
      markerFound = YES; 
      break; 
     } else if (0xdb == markerValue) { 
      dqtFound = YES; 
      break; 
     } else { 
      NSData *lengthData = [fileHandle readDataOfLength:2]; 
      currentOffset += 2; 
      NSInteger length = (unsigned short)*(unsigned short *)[lengthData bytes]; 
      length = NSSwapBigShortToHost(length); 
      length -= 2; 
      currentOffset += length; 
      [fileHandle seekToFileOffset:currentOffset]; 
     } 
    } 

这给你的偏移量APP3标记,柜面你需要添加你自己的app3标记,你可以使用类似的方法。