iOS:在 Marker APP3 上访问 JPEG 元数据

发布于 2024-11-09 12:24:20 字数 864 浏览 0 评论 0原文

我一直在使用 Exif 标签通过以下方式在 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 来运行此应用程序。

I have been using the Exif tags to store some data on jpeg files in the following manner:

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

Now, I would like to use a custom Application Marker (APP3 at 0xFFE3) instead of Exif Marker.

(Refer - http://www.ozhiker.com/electronics/pjmt/jpeg_info/app_segments.html)

Could someone point me in the right direction.

PS: I am using a jailbroken iPad for this app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咿呀咿呀哟 2024-11-16 12:24:20

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

创建文件句柄:

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 标记,则可以使用类似的方法。

Okay, it seems we have to go via file handler way for this. Here is what I did, though there may be a better way to do this.

Create a File handle:

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

Then iterate the file contents till you find a desired tag:

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];
        }
    }

This gives you the offset to the APP3 marker, incase you need to add your own app3 marker you can use a similar approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文