简体   繁体   English

如何在NSView上绘制NSImage?

[英]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. 对于使用Objective C绘制图像,我是一个新手。我已经在iPhone开发中完成了图像绘制,但是现在我想在Mac上绘制图像。 In short, what is the Mac equivalent of the iPhone code below? 简而言之,Mac相当于下面的iPhone代码?

- (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. 假设您不希望任何图像透明度和构图效果,这应该可以工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM