Re: Drawing partially transparent gradient
Christiaan Hofman <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sep 7, 2009, at 2:03, Scott Stevenson wrote: > > On Sep 6, 2009, at 4:39 PM, Christiaan Hofman wrote: > >> I am trying to draw an NSGradient starting from a light gray >> (though that's irrelevant) to clearColor over a (light) background. >> However, for some reason the gradient becomes dark in the middle, >> while near the ends it looks as I expected. I already tried setting >> the compositeOperation explicitly to NSCompositeSourceOver, but >> that did not help (other operations are certainly wrong). Also >> playing with the CG blend mode got me nowhere. > > Without actually trying this out myself, here's my hunch: [NSColor > clearColor] is defined as 0.0 alpha of black, not white: > > NSLog(@"clearColor: %@", [NSColor clearColor]); > > clearColor: NSCalibratedWhiteColorSpace 0 0 > > The first '0' means it's 0.0 for the white value. So the gradient is > not transitioning just the alpha value, but the white value as well. > The effect you're seeing is probably the same as what you'd see in > Photoshop. > > My guess is that creating an NSColor with 0.0 for alpha and the same > white value as your start color will produce the result you want. > > - Scott Yes, that's it! Thanks! Christiaan