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: 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
2004-09-08Setting the ColorSync profile for a NSBitmapImageRep object

Posted: 2004-09-08


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.