Skip navigation.
 
mlRe: tinting an NSImage
FROM : R. Scott Thompson
DATE : Mon Oct 04 20:32:09 2004

On Oct 2, 2004, at 4:26 PM, Mark Lilback wrote:

> I'm working on a project that needs to take a bitmap image provided by
> the user and transform it so that it will print on a printing press
> with a single color specified by the user (basically grayscale with an
> arbitrary color instead of black).
>
> The Monochrome Image sample code shows how to get a grayscale image,
> but I'd need to switch from NSCalibratedWhiteColorSpace to a color
> space I create.
>
> I can't find much documentation on NSNamedColorSpace and
> NSCustomColorSpace, except the docs for NSDrawBitmap() says that
> NSCustomColorSpace says to use the current colorspace of the graphics
> context. So I set the colorspace using CGContextSetStrokeColorSpace
> and CGContextSetFillColorSpace but then [NSBitmapImageRep
> initWithBitmapDataPlanes:...] reports "Bad colorspace name
> NSCustomColorSpace".
>
> I've also tried creating a CSImageRef from the monochrome bitmap but
> substituting a colorspace create with CGColorSpaceCreateCalibratedGray
> using the desired color as the black point. That doesn't work either.
>
> Does anyone know how to use NSCustomColorSpace and/or
> NSNamedColorSpace? Or better yet, does anyone have a better idea on
> how to switch a grayscale image to use another color as the black
> point?
>
> TIA


There's a routine in NSBitmapImageRep called
colorizeByMappingGray:toColor:blackMapping:whiteMapping:.  I've never
used it myself... I just ran across it this afternoon.  It might do
what you want though.

Scott

Related mailsAuthorDate
mltinting an NSImage Mark Lilback Oct 2, 23:26
mlRe: tinting an NSImage Douglas A. Welton Oct 3, 13:22
mlRe: tinting an NSImage R. Scott Thompson Oct 4, 20:32