Re: NSBitmapImageRep and drawing with alpha
Re: NSBitmapImageRep and drawing with alpha
- Subject: Re: NSBitmapImageRep and drawing with alpha
- From: Brian Webster <email@hidden>
- Date: Thu, 16 Aug 2001 13:52:51 -0500
on 8/16/01 1:26 PM, email@hidden at
email@hidden wrote:
>
I'm trying to use NSBitmapImageRep to load a 'png' or 'tif' file with an
>
associated alpha channel and then draw it into my custom view.
>
>
The image is drawn but the alpha is drawn in black. I've tried turning on
>
Alpha in the class but that makes no difference.
>
>
Is there something I'm missing here?
In order to prevent the pixels in the alpha channel from being drawn, you
need to use the NSCompositeSourceOver compositing operation. If you're
using NSImageRep's draw, drawAtPoint:, or drawInRect: methods, these all use
NSCompositeCopy, which will ignore the alpha. You should create a new
NSImage and then add your bitmap representation to the image. Then you can
use NSImage's compositeToPoint:operation: and pass in the correct
compositing operation.
NSBitmapImageRep *myBitmap;
NSImage *myImage = [[NSImage alloc] initWithSize:[myBitmap size]];
[myImage addRepresentation:myBitmap];
...
[myImage compositeToPoint:location operation:NSCompositeSourceOver];
--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster/