• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Draw rounded NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Draw rounded NSImage


  • Subject: Re: Draw rounded NSImage
  • From: John Wright <email@hidden>
  • Date: Mon, 7 Dec 2009 13:05:53 -0700

Thanks Gideon, that worked.

On Sun, Dec 6, 2009 at 9:03 PM, Gideon King <email@hidden> wrote:

> Your code restores the graphics state, which will remove your rounded rect
> clipping path, before you draw the image.
>
> If you draw the image before restoring the graphics state, you should be
> OK.
>
> Also you should not need to explicitly set the winding rule.
>
> HTH
>
> Gideon
>
> On 05/12/2009, at 7:22 AM, John Wright wrote:
>
> > I am trying to create a NSImage or NSImageCell with rounded corners
> > inside a NSTableView. I can't get anything to work. Here is the best I
> > have so far inside my custom NSCell:
> >
> > - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView
> {
> >   if (thumbnailLink) {
> >         NSURL *url = [NSURL URLWithString:thumbnailLink];
> >         if (url) {
> >                 NSRect imageFrame = [self
> _imageFrameForInteriorFrame:frame];
> >                 NSImage *image = [[NSImage alloc]
> initWithContentsOfURL:url];
> >                 [image setScalesWhenResized:YES];
> >                 [image setSize:NSMakeSize(IMAGE_HEIGHT, IMAGE_WIDTH)];
> >
> >                 [NSGraphicsContext saveGraphicsState];
> >                 imageFrame = NSInsetRect(imageFrame, 1, 1);
> >                 NSBezierPath *clipPath = [NSBezierPath
> > bezierPathWithRoundedRect:imageFrame cornerRadius:5.0];
> >                 [clipPath setWindingRule:NSEvenOddWindingRule];
> >                 [clipPath addClip];
> >                 [NSGraphicsContext restoreGraphicsState];
> >                 [image drawInRect:imageFrame fromRect:NSMakeRect(0, 0,
> > 0, 0) operation:NSCompositeSourceIn fraction:1.0];
> >                 [image release];
> >         }
> > }
> > ...
> >
> > Any ideas on how to do this?.
>
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Draw rounded NSImage (From: John Wright <email@hidden>)
 >Re: Draw rounded NSImage (From: Gideon King <email@hidden>)

  • Prev by Date: Re: Question about aliasing (analog clock hands)
  • Next by Date: Re: Untitled Document Leak
  • Previous by thread: Re: Draw rounded NSImage
  • Next by thread: Re: Draw rounded NSImage
  • Index(es):
    • Date
    • Thread