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

Drawing an NSImage


  • Subject: Drawing an NSImage
  • From: Andreas Schweizer <email@hidden>
  • Date: Wed, 18 Jul 2001 17:10:50 +0200

Hi!

I have a subclass of NSView and want to draw an NSImage in my drawRect method. Using the code below, the drawing does not occur until I select the window that contains the NSView. Am I missing something here? (e.g. a 'flush' operation?)

Interesting detail: When I comment out the [self lock/unlockFocus], the NSImage is drawn immediately, but into a completely unrelated window of my program...

What am I doing wrong??

Thanks,
Andy

- (void)drawRect:(NSRect)r
{
NSSize viewSize;
NSSize imageSize;
NSPoint imageTargetPoint;

[self lockFocus];

// erase entire bitmap area
[[NSColor whiteColor] set];
NSRectFill([self bounds]);

// draw selected image
imageSize = [theImage size];
viewSize = [self bounds].size;
imageTargetPoint = NSMakePoint(0, viewSize.height - imageSize.height);
[theImage compositeToPoint:imageTargetPoint operation:NSCompositeSourceOver];

[self unlockFocus];
}


  • Prev by Date: Checkbox in a TableView cell
  • Next by Date: Re: Oops, I stand corrected. (was: Collection of Cocoa & objc questions from a "newbie")
  • Previous by thread: Re: Checkbox in a TableView cell
  • Next by thread: Re: Drawing an NSImage
  • Index(es):
    • Date
    • Thread