嵌入从可可mac应用程序创建的JPEG中的颜色配置文件sRGB



我在我的可可mac应用程序中使用以下代码创建JPEG。如何在创建的JPEG中嵌入srgb颜色配置文件?

NSImage* savedImage = [[NSImage alloc] initWithSize:NSMakeSize(600, 600)];
[savedImage lockFocus];
//draw here 
[savedImage unlockFocus];
NSBitmapImageRep* savedImageBitmapRep = [NSBitmapImageRep imageRepWithData:[savedImage TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:1.0]];
NSDictionary* properties = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithFloat:1.0], kCGImageDestinationLossyCompressionQuality,
                            nil];
NSMutableData* imageData = [NSMutableData data];
CGImageDestinationRef imageDest =  CGImageDestinationCreateWithData((CFMutableDataRef) imageData, kUTTypeJPEG, 1, NULL);
CGImageDestinationAddImage(imageDest, [savedImageBitmapRep CGImage], (CFDictionaryRef) properties);
CGImageDestinationFinalize(imageDest);
// Do something with imageData
if (![imageData writeToFile:[@"~/Desktop/test.jpg" stringByExpandingTildeInPath] atomically:NO])
    NSLog(@"Failed to write imageData");

不知道如何使用这些高级API来实现这一点。我通过自己将所需的IFD添加到JPEG数据中来完成这项工作。

最新更新