Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Creating text image in code

 
   Mac (Home) -> Programmer Help RSS
Next:  Handling Events in Dock Menu in Carbon.  
Author Message
google

External


Since: Jun 28, 2005
Posts: 15



(Msg. 1) Posted: Thu May 11, 2006 6:56 am
Post subject: Creating text image in code
Archived from groups: comp>sys>mac>programmer>help (more info?)

What's the easiest (i.e least amount of code) way to generate an
NSImage with black text on a transparent background? It needs to be
done in code, as the text will be constantly changing.

(The last time I did any 2D graphics programming was in QuickDraw, not
even sure what API/framework to look in now. It's just for a 1-day
hobby project, but I'd love to try and get it done all the same).

TIA!
Mike.
Back to top
Login to vote
google

External


Since: Jun 28, 2005
Posts: 15



(Msg. 2) Posted: Thu May 11, 2006 8:30 am
Post subject: Re: Creating text image in code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

David Phillip Oster wrote:
> Meditate on
>
> + [NSGraphicsContext graphicsContextWithBitmapImageRep: ...
>
> It provides a bridge between something in an NSImage and a place where
> you can draw text.

Hommmmmm...Wink

Thanks! Was that introduced in 10.4? I can't find it in the 10.3 docs.
Back to top
Login to vote
google

External


Since: Jun 28, 2005
Posts: 15



(Msg. 3) Posted: Thu May 11, 2006 9:09 am
Post subject: Re: Creating text image in code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Patrick Machielse wrote:
> Maybe the easiest way to do what you want is:
>
> * create an image of suitable proportions
> * -[yourImage lockFocus]
> * -[yourString drawAtPoint:withAttributes:]
> * -[yourImage unlockFocus]

Ah, perfect! And I can use sizeWithAttributes: to determine the size
beforehand and centre the text appropriately.

Thanks to all for the replies!

(FYI, if anyone's interested, the project is a countdown timer to a big
sporting event - European Cup rugby final - in which the counter text
is the actual window, with the colour of the text slowly changing to
red and growing in size, as the big date draws near. Sounds tacky, I
know, but I know people who'll love this).
Back to top
Login to vote
David Phillip Oster

External


Since: Jul 21, 2005
Posts: 150



(Msg. 4) Posted: Thu May 11, 2006 2:32 pm
Post subject: Re: Creating text image in code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1147355802.221887.48110.RemoveThis@i39g2000cwa.googlegroups.com>,
google.RemoveThis@whooley.utvinternet.com wrote:

> What's the easiest (i.e least amount of code) way to generate an
> NSImage with black text on a transparent background? It needs to be
> done in code, as the text will be constantly changing.

Meditate on

+ [NSGraphicsContext graphicsContextWithBitmapImageRep: ...

It provides a bridge between something in an NSImage and a place where
you can draw text.
Back to top
Login to vote
Patrick Machielse

External


Since: Jun 28, 2005
Posts: 92



(Msg. 5) Posted: Thu May 11, 2006 5:42 pm
Post subject: Re: Creating text image in code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

<google DeleteThis @whooley.utvinternet.com> wrote:

> David Phillip Oster wrote:
> > Meditate on
> >
> > + [NSGraphicsContext graphicsContextWithBitmapImageRep: ...
> >
> > It provides a bridge between something in an NSImage and a place where
> > you can draw text.
>
> Hommmmmm...Wink
>
> Thanks! Was that introduced in 10.4? I can't find it in the 10.3 docs.

Maybe the easiest way to do what you want is:

* create an image of suitable proportions
* -[yourImage lockFocus]
* -[yourString drawAtPoint:withAttributes:]
* -[yourImage unlockFocus]

patrick
Back to top
Login to vote
Patrick Machielse

External


Since: Jun 28, 2005
Posts: 92



(Msg. 6) Posted: Thu May 11, 2006 7:22 pm
Post subject: Re: Creating text image in code [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

<google DeleteThis @whooley.utvinternet.com> wrote:

> Patrick Machielse wrote:
> > Maybe the easiest way to do what you want is:
> >
> > * create an image of suitable proportions
> > * -[yourImage lockFocus]
> > * -[yourString drawAtPoint:withAttributes:]
> > * -[yourImage unlockFocus]
>
> Ah, perfect! And I can use sizeWithAttributes: to determine the size
> beforehand and centre the text appropriately.

You're getting the hang of it...

> (FYI, if anyone's interested, the project is a countdown timer to a big
> sporting event - European Cup rugby final - in which the counter text
> is the actual window, with the colour of the text slowly changing to
> red and growing in size, as the big date draws near. Sounds tacky, I
> know, but I know people who'll love this).

Rugby players, no doubt!

Anyway, why not just put your drawing code in you custom view's
drawRect: method?

patrick
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Creating a Virtual Audio Driver? - Hi, Just wondering if anyone has any thoughts or experience on creating what I think you would call a "virtual" audio driver for OS X? I want to create an audio driver that goes between a standard application (outputting standard wave audio...

NSView: clipping when creating PDF? - I'm having troubles using dataWithPDFInsideRect to generate a PDF of an NSView which contains other views. The inside views do lots of NSBezierPath drawing, and rely on clipping to keep the drawing inside the views. This works fine for drawing to the....

Creating folders - a Windows Programmer Question - OK, I've been beating my head on this for a couple of days. Here's my question: In Windows if I want to create a directory path, I can recursively call a create directory function and build each part of the path using mkdir() or CreateDirectory(). ...

moving code around - I frequently copy my source code to and from my mac-formatted disks to disks formatted with NTFS... in earlier days I heard that you can loose 'resource forks' if you do this sort of thing... but now we have OS X..... is this something I still need to...

any sample code out there that shows NSTimeZone? - i'm writing a routine that determines sunrise and sunset in an online game but i need to know the user's local time zone to offset the calculations by yes, u saw "systemtimezone" but no sample code that shows how everything's supposed to work.
       Mac (Home) -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact