Keeping grayscale image grayscale
Keeping grayscale image grayscale
- Subject: Keeping grayscale image grayscale
- From: Jonathan Taylor <email@hidden>
- Date: Mon, 10 Oct 2011 18:43:40 +0100
I'm working with 16-bit grayscale images, and for the most part I'm just manipulating bits within NSBitmapImageRep objects. However for convenience it would be nice to do some stuff with NSImages, particularly when rescaling and suchlike. The problem is that whenever I draw into such an NSImage it gets converted to 3x8 bit RGB. Is there a simple way I can force things to stay grayscale, or am I fighting a losing battle here. The code snippet I have looks like this:
NSImage *srcImage = [[NSImage alloc] initWithContentsOfFile:thePath];
NSImage *destImage = [srcImage copy]; // Attempt to "encourage" same 16-bit grayscale format as source
[destImage setSize:destSize]; // Shrink dest image
// Draw image into a new image at reduced size
// This causes the result to be saved as a 3x8 bit RGB TIFF (which is not what I want!)
[destImage lockFocus];
[srcImage drawInRect:destRect fromRect:srcRect operation:NSCompositeCopy fraction:1.0];
[destImage unlockFocus];
[[destImage TIFFRepresentation] writeToFile:destFile atomically:NO];
Does anyone have any suggestions?
Thanks
Jonny_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden