Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a couple of CGContext questions



On Jan 31, 2007, at 08:19 AM, Steve Christensen wrote:

I'm not sure I understand the double counting part, but I understand that once an operation has been performed on a context that the resulting pixels take into account the pixel's previous alpha value as well as that of the context's alpha. All I'm saying is that I'd like to be able to do things like this:

theAlpha = CGContextGetAlpha(theContext);

CGContextSetAlpha(theContext, theAlpha * 0.5);
CGContextStrokeRect(theContext, theRect);
CGContextSetAlpha(theContext, theAlpha);

Just to this instead: CGContextSetRGBStrokeColor(theContext, r, g, b, 0.5); CGContextStrokeRect(theContext, theRect);

That will get you exactly what you are looking for.

In this case, I'd expect to see a rectangle drawn at half the current context alpha. I might have, for example, just drawn an image at an arbitrary alpha on top of some background, then wanted to draw a border at half that alpha.

And then here you'd get one drawn at 1/4 alpha.

I could obviously just carry around an alpha value to be used for all the drawing and then use that for calculating relative alpha values. But since the context must already know what its current alpha value is, it seems reasonable to be able to just ask when needed.

The context alpha is basically applied to all pixels, along with their own alpha value. Imagine the context alpha as a big switch that says "how much of this context's pixels do I let bleed through" and each pixel's alpha as "how much of the previous pixel do I let bleed through".


What makes this more interesting is that CGContextSetAlpha() only works until the next call of the same (or a GState restore that restores a previous setting of it). So it's not quite one or the other. And the inherent danger of having a "getter" and doing math on it is that you can set a value, it gets clipped, and when you get it you get a value that is not what you expect.
--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.


David Duncan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >a couple of CGContext questions (From: Steve Christensen <email@hidden>)
 >Re: a couple of CGContext questions (From: Laurence Harris <email@hidden>)
 >Re: a couple of CGContext questions (From: Steve Christensen <email@hidden>)
 >Re: a couple of CGContext questions (From: David Duncan <email@hidden>)
 >Re: a couple of CGContext questions (From: Steve Christensen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.