how to change UIKit UIImage:drawInRect method to AppKIt NSImage:drawInRect Method

Posted by user322111 on Stack Overflow See other posts from Stack Overflow or by user322111
Published on 2010-04-21T09:53:30Z Indexed on 2010/04/22 20:03 UTC
Read the original article Hit count: 465

Filed under:

Hi, i'm porting an iphone app to Mac app,there i have to change all the UIKit related class to AppKit. if you can help me on this really appreciate. is this the best way to do below part..

Iphone App-->using UIKit

UIGraphicsPushContext(ctx);
[image drawInRect:rect];
UIGraphicsPopContext();

Mac Os--Using AppKit

[NSGraphicsContext saveGraphicsState];
NSGraphicsContext * nscg = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES];
[NSGraphicsContext setCurrentContext:nscg];
NSRect rect = NSMakeRect(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
[NSGraphicsContext restoreGraphicsState];

[image drawInRect:rect fromRect:NSMakeRect( 0, 0, [image size].width, [image size].height )
        operation:NSCompositeClear
         fraction:1.0];

© Stack Overflow or respective owner

Related posts about cocoa