簡體   English   中英

如何在NSView上繪制NSImage?

[英]How do I draw a NSImage onto a NSView?

對於使用Objective C繪制圖像,我是一個新手。我已經在iPhone開發中完成了圖像繪制,但是現在我想在Mac上繪制圖像。 簡而言之,Mac相當於下面的iPhone代碼?

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

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

}

假設您不希望任何圖像透明度和構圖效果,這應該可以工作。

-(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