• 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: Drawing into an NSImage?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing into an NSImage?


  • Subject: Re: Drawing into an NSImage?
  • From: David Remahl <email@hidden>
  • Date: Sun, 03 Mar 2002 14:22:35 +0100

> Is it possible to draw into an image? For example, I'd like to
> draw using NSBezierPath methods into an NSImage. I don't want to
> draw into an NSView because the rendered image will become
> fairly complex and shouldn't need to be completely re-rendered
> each redraw.
>
> Or, if I would need to render in an offscreen NSView, how to I
> move that rendered content into an NSImage? My goal is to render
> an image and place into an NSImageView.
>
> I am new at this. I've checked the archives. I've scoured the
> web and all developer documentation and I just don't get it.
>
> Thanks,
> Philip

All you need to do is to lockFocus on the image:

NSImage* img = [[NSImage alloc] initWithSize:NSMakeSize(200,200)];
NSBezierPath* bezPath = [NSBezierPath bezierPath];

[img lockFocus];
[bezPath moveToPoint:NSMakePoint(10,10)];
[bezPath lineToPoint:NSMakePoint(10,190)];
[bezPath lineToPoint:NSMakePoint(100,100)];
//Complex stuff
[bezPath stroke];
[img unlockFocus];

[imageView setImage:img];
[img release];

Just typing directly into email. May or may not work imediately.

/ david
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Drawing into an NSImage? (From: Philip Weaver <email@hidden>)

  • Prev by Date: Re: Current row/column string value...
  • Next by Date: Re: Drag types from iTunes
  • Previous by thread: Drawing into an NSImage?
  • Next by thread: How to identify a menu item?
  • Index(es):
    • Date
    • Thread