Re: Can NSImage use image masks?
Re: Can NSImage use image masks?
- Subject: Re: Can NSImage use image masks?
- From: Andrew Hunter <email@hidden>
- Date: Tue, 11 May 2004 12:21:38 +0100
On 9 May 2004, at 17:42, Jesus De Meyer wrote:
Can I use an NSImage the way I can in Carbon with CopyMask? I mean
other than using the built in mask from a TIFF file for example?
I need to draw an image and use an other image as a mask. Anyone know
how to do this?
Yes, but how you do it is a bit different. The compositing operation
you need is NSCompositeSourceIn (or NSCompositeSourceAtop, depending on
the effect you want to create). You'll need to create a copy of the
image whose mask you want to use, then use - [NSImage lockFocus] on it,
then composite the second image using the NSCompositeSourceIn operator.
Finally, unlock the focus: the NSImage copy now contains the picture
formed from the alpha channel of the first and the colours of the
second. Ie:
NSImage* one, *two; // Images in
... // Setup one & two
NSImage* result = [one copy];
[result lockFocus];
[two compositeToPoint: NSMakePoint(0,0) operation: NSCompositeSourceIn];
[result unlockFocus];
// result now contains the final image
... // Do something with the result
[result release];
I don't think there's a way to do this without creating a copy of the
first image. If the first image is (say) only a 1-bit image, you may
have to create a new image filled with a clear background and draw it
there rather than just calling copy to get the best results.
Andrew.
--
Andrew Hunter.
http://www.logicalshift.demon.co.uk
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.