I almost have colorizeByMappingGray working...
I almost have colorizeByMappingGray working...
- Subject: I almost have colorizeByMappingGray working...
- From: Christopher Drum <email@hidden>
- Date: Wed, 2 Feb 2005 23:58:11 -0800
...but I'm having some troubles. I'm finding the documentation on NSImage, NSImageRep, and NSBitmapImageRep to be kind of confusing, although I have made some good personal progress in my skills today regarding it all.
Really having a hard time getting the colorizeByMappingGray:toColor:blackMapping:whiteMapping: method to work, but I think I'm close. I'm slapping together some quick and dirty code to try out the process, and I have the following in my custom view...
- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil) {
//Grab the source image data
source = [NSImage imageNamed:@"grayscale"];
NSData *dataS = [source TIFFRepresentation];
//Grab the bitmapImageRep out of the source image and manipulate it
rep = [NSBitmapImageRep imageRepWithData:dataS];
[rep colorizeByMappingGray:0.4
toColor:[NSColor redColor]
blackMapping:[NSColor blueColor]
whiteMapping:[NSColor yellowColor]];
//Cram the modified bitmapImageRep into a new image
NSData *dataD = [rep TIFFRepresentation];
destination = [[[NSImage alloc] initWithData:dataD] retain];
}
return self;
}
- (void)drawRect:(NSRect)rect
{
//Display the new image
[destination compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];
}
The source image is an 8BPP image with alpha. This ALMOST works. The image displays in the custom view complete with alpha mask, and it is clearly altered by the colorizeByMappingGray: call. Unfortunately, all that seems to do is darken the grayscale image, not colorize it. If I comment out the colorization, the image displays normally. So, I believe I'm passing the rep from the source image into the destination image OK. The only clue I can come up with about what's happening is that both [source representations] and [destination representations] report back a single NSBitmapImageRep of NSCalibratedWhiteColorSpace. It makes sense to me that if the destination's colorspace is not RGB, then I can't see the colors I've applied during colorization. However, I don't see how to set the colorspace to RGB for my destination image or really for the image rep I'm cramming into the destination image.
Any ideas or suggestions? Or (dare I dream?) source code examples?
------------------------------------------------------------------
Christopher Drum
http://homepage.mac.com/christopherdrum
Check out FileWrangler, my five-star rated (MacUpdate, VersionTracker) Cocoa app written in Objective-C for the batch renaming of files.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden