• 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: NSImage lockFocus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage lockFocus


  • Subject: Re: NSImage lockFocus
  • From: Andrew Platzer <email@hidden>
  • Date: Thu, 27 Sep 2001 11:35:52 -0700

On Saturday, September 22, 2001, at 06:51 , email@hidden wrote:

Now I've taken a look at all the drawing related docs I could find, and it seems to me that one can draw into an NSView even when outside of the drawRect: function as long as one uses the 'lockFocus' call. I also noticed that NSImage has this very same call. So logic would follow that if I locked focus on an NSImage, I could draw into it (provided its size was set correctly beforehand.)

As to drawing into an view outside of the normal update code, calling lockFocus/unlockFocus is fine but if the window is buffered, you won't see anything unless you call [[view window] flushWindow] afterwards. In general, you should try to avoid drawing outside of the normal drawRect: call since it has the potential not work. You should only draw explicitly if you are inside some kind of tracking loop which doesn't give the NSApplication the chance to redraw or you know that only a small area is dirty.

Needless to say, it doesn't seem to work.. I have even gone so far as to try to lockFocusOnRepresentation (after adding an appropriate representation with the proper number of colours and size,) but that fails miserably as apparently NSImageReps do not respond to the -init call!

There should be no reason you can't draw. Did you remember to set the size of the new image? Something like this should work:

NSImage* image = [[NSImage alloc] initWithSize:NSMakeSize(100, 100)];
[image lockFocus];
[[NSColor redColor] set];
NSRectFill(NSMakeRect(0, 0, 100, 100));
[image unlockFocus];

Andrew
__________________________________________________________________
A n d r e w P l a t z e r
A p p l i c a t i o n F r a m e w o r k s
A p p l e


References: 
 >NSImage lockFocus (From: email@hidden)

  • Prev by Date: Re: Autobanking
  • Next by Date: Re: NSMovieView uses 3-8% CPU after playing a sound?
  • Previous by thread: Re: NSImage lockFocus
  • Next by thread: Project Builder weirdness...
  • Index(es):
    • Date
    • Thread