嵌入从cocoa mac app创建的JPEG中的颜色配置文件sRGB

时间:2012-02-11 16:16:10

标签: objective-c macos cocoa

我在cocoa mac app中使用以下代码来创建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");

1 个答案:

答案 0 :(得分:0)

不知道如何使用这些高级API执行此操作。我是通过自己将所需的IFD添加到JPEG数据中完成的。