• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Drawing text with alpha
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing text with alpha


  • Subject: Re: Drawing text with alpha
  • From: Ricky Sharp <email@hidden>
  • Date: Tue, 21 Aug 2007 20:17:04 -0500


On Aug 21, 2007, at 8:06 PM, I. Savant wrote:

On Aug 21, 2007, at 8:41 PM, Phil wrote:
This seems to be a common question related to drawing graphics but I haven't found an answer that addresses alpha and text. I've got a simple NSView subclass which draws a blue background and want to draw text with it's background alpha set to .1. But as the alpha is decreased, the background becomes black. My example (how not to do it) code:


Maybe I'm not reading very carefully (it's late), but have you tried *not* specifying the background of your text? In other words, don't specify a color for the NSBackgoundColorAttributeName.

I also had trouble getting the code to work as the OP wanted (I'll blame it on being late here too :)


Anyhow, I know that a workaround would be to do the following:

1) As I.S. states, do not apply any background color to the text.
2) Build an attributed string and obtain its size
3) Create an NSRect with your origin and string's size, set the current context's color to your 0.1 alpha white color, and then use NSRectFillUsingOperation (yourRect, NSCompositeSourceOver).
4) Draw your attributed string into yourRect.


One thing I did try in the original code was to bracket the string drawing with:

	NSGraphicsContext* theContext = [NSGraphicsContext currentContext];

	[theContext saveGraphicsState];
	[theContext setCompositingOperation:NSCompositeSourceOver];

... draw string

	[theContext restoreGraphicsState];

I figured that string rendering may honor the compositing operation, but it did not.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Drawing text with alpha
      • From: Phil <email@hidden>
References: 
 >Drawing text with alpha (From: Phil <email@hidden>)
 >Re: Drawing text with alpha (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: Drawing text with alpha
  • Next by Date: Re: Drawing text with alpha
  • Previous by thread: Re: Drawing text with alpha
  • Next by thread: Re: Drawing text with alpha
  • Index(es):
    • Date
    • Thread