Re: Drawing into an NSImage?
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.