Scsm326 Scsm326 - 6 months ago 43
Objective-C Question

How do I draw a NSImage onto a NSView?

I'm pretty new to drawing images in general with Objective C. I have done image drawing in iPhone development, but now I want to do so on a Mac. In short, what is the Mac equivalent of the iPhone code below?

- (void) drawRect: (CGRect) rect
[super drawRect:rect];

UIImage *anotherimage = [UIImage imageNamed:@"alert.png"];
CGPoint imagepoint = CGPointMake(10,0);
[anotherimage drawAtPoint:imagepoint];



This should work, assuming you don't want any image transparency and composition effects.

    [super drawRect:dirtyRect];
    NSImage *anotherImage = [NSImage imageNamed:@"alert.png"];
    [anotherImage drawAtPoint:NSMakePoint(10,0) fromRect:rectToDrawImage operation:NSCompositeCopy fraction:1.0];