Drawing an NSImage
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];
}