Technical Q&A QA1369

Setting the ColorSync profile for a NSBitmapImageRep object

Q:  I'd like to associate a ColorSync profile with a given NSBitmapImageRep object for color-matching purposes. Is there a simple way to do this?

A: I'd like to associate a ColorSync profile with a given NSBitmapImageRep object for color-matching purposes. Is there a simple way to do this?

You can associate a ColorSync profile with a NSBitmapImageRep object containing pixel data produced by decoding a TIFF, JPEG, GIF or PNG file using the -setProperty: method and the NSImageColorSyncProfileData property.

Here's a short code snippet showing how it's done:

Listing 1  Setting the ColorSync profile for a NSBitmapImageRep object.

//
// imageRepWithProfileAtPath
//
// Associate a given file-based ColorSync profile with
// a NSBitmapImageRep object
//
// Inputs:
//
//    aPath - file path for a ColorSync profile
//
// Outputs:
//
// - returns a new NSBitmapImageRep object, created 
//    by copying the receiver and applying the ColorSync 
//    profile.

@implementation NSBitmapImageRep (MoreColorMethods)

- (NSBitmapImageRep *) imageRepWithProfileAtPath:(NSString *) pathToProfile
{
    id result = [self copy];

        // build a NSData object for our ColorSync profile file
    id profile = [NSData dataWithContentsOfFile: pathToProfile];

        // now set the ColorSync profile for the object
    [result setProperty:NSImageColorSyncProfileData withValue:profile];

    return [result autorelease];
}

@end


Document Revision History


DateNotes
2018-06-04

Moved to Retired Documents Library.

2004-09-08

New document that setting the ColorSync profile for a NSBitmapImageRep object