Another newbie request.

Member
Posts: 22
Joined: 2007.05
Post: #1
Can anyone point me to some sample code that illustrates:

1.) Drawing a partial segment of a source image (png) to an NSImageView
2.) Drawing a partial segment of a source image (png) to a Custom View

Here is a little of what I am trying to get to work (using the NSImageView approach):

Code:
- (NSImage *)drawCard
{
    NSImage * cardSheet = [[NSImage alloc] initWithContentsOfFile:@"cardSheet.png"];
    
    NSSize cardInSheetSize;
    cardInSheetSize.height = 70;
    cardInSheetSize.width = 50;
    
    NSRect srcRect;
    (srcRect.origin).x = 0.0;
    (srcRect.origin).y = 0.0;
    srcRect.size = cardInSheetSize;
    
    NSRect dstRect;
    dstRect.origin = NSZeroPoint;
    dstRect.size = cardInSheetSize;
    
    NSImage * card = [[NSImage alloc] initWithSize:cardInSheetSize];
    [card lockFocus];
    [cardSheet drawInRect:dstRect fromRect:srcRect operation:NSCompositeCopy fraction:1.0];
    [card unlockFocus];
    
    return card;
}

I am calling it with:

Code:
[nextCardImage setImage:[deck drawCard]];

nextCardImage is an NSImageView Outlet.

Thanks for any help.
Quote this message in a reply
Post Reply 


Messages In This Thread
Another newbie request. - hypnotx - Jun 8, 2007 08:57 PM
Another newbie request. - Taxxodium - Jun 9, 2007, 01:13 AM
Another newbie request. - hypnotx - Jun 10, 2007, 02:03 AM
Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Request] Pong Source & One Question McSpider 6 6,776 Sep 18, 2011 07:21 AM
Last Post: fudog
  newbie request direction Teehee 3 5,443 Jul 27, 2011 09:57 AM
Last Post: AndyKorth